// JavaScript Document

function checkBlank(mes,ob)
{
	if(ob.value=="")
	{
		ob.focus();
		alert(mes);
		return false;
	}
}

function checkChecked(mes,ob)
{
	if(ob.checked!=true)
	{
		ob.focus();
		alert(mes);
		return false;
	}
}

function checkBlankacc(mes,ob)
{
	if(ob.value=="0")
	{
		ob.focus();
		alert(mes);
		return false;
	}
}


function checkEmail(mes,ob)
{
	if ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(ob.value)) == false)
	{
				ob.focus();
				alert(mes);
				return false;
	}
}
function checkUsername(msg,obj)
{

		var string1="qazwsxedcrfvtgbyhnujmikolpQAZWSXEDCRFVTGBYHNUJMIKOLP" + "1234567890";

		var val=obj.value;

		var op=new String();

	    op.value=val;

	     	 for(var i=0;i<op.value.length;i++)

			   {

		    	 if(string1.indexOf(op.value.charAt(i))==-1)

			   		{

			   			alert(msg);

						obj.focus();

						return false;

			        }

			   }

}

function NewWindow(mypage,myname,w,h,scroll,pos)
{
	if(pos=="random")
	{
	LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
	TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if(pos=="center")
	{
	LeftPosition=(screen.width)?(screen.width-w)/2:100;
	TopPosition=(screen.height)?(screen.height-h)/2:100;
	}
	else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=no';
	win=window.open(mypage,myname,settings);
	
}


function NewWindow1()
{
	un=document.frm1.member_username.value;
	NewWindow('member_pop.php?un='+un,'mywin','300','100','yes','center');
}



function checkNumber(mes,ob)
{
	var i=0;
	var n=ob.value;
	var len=n.length;
	
	var j;
	var flag;
	i=0;
	while(i<len)
	{
			flag=0;
			for(j=0;j<10;j++)
			{
				if(n.charAt(i)==j || n.charAt(i)==".")
				{
					flag=1;
				}
			}
			if(flag==0)
			{
				ob.focus();
				alert(mes);
				return false;
			}
			i=i+1;
	}
}


function checkDate(mes,ob)
{
	var i=0;
	var n=ob.value;
	var len=n.length;
	
	var j;
	var flag;
	i=0;
	
	if(len!=10)
	{
		ob.focus();
		alert(mes);
		return false;
	}
	
	while(i<len)
	{
			flag=0;
			for(j=0;j<10;j++)
			{
				if(n.charAt(i)==j || n.charAt(i)=="/")
				{
					flag=1;
				}
			}
			if(flag==0)
			{
				ob.focus();
				alert(mes);
				return false;
			}
			i=i+1;
	}
	
	if(n.charAt(2)!="/" && n.charAt(5)!="/")
	{
		ob.focus();
		alert(mes);
		return false;
	}
	
	
	// date validation
	var day= n.substring(0,2);
	
	var month= n.substring(3,5);
	var year= n.substring(6,10);
	
	//alert(month);
	

	if (day>31) 
	{
		alert("Please enter the proper date.");
		return false;
	}
	if (month>12) 
	{
		alert("Please enter valid month");
		return false;
	}	
	
	
	if ((month=="04" || month=="06" || month=="09" || month=="11"  ) && day=="31") 
	{
		alert("Please enter the valid  month.");
		return false;
	}	
	if (month == 02)
	{ // check for february 29th
		var isleap = (year % 4 == 0 );
		if (day>29 || (day==29 && !isleap))
		{
			alert("February " + year + " doesn't have " + day + " days!");
			return false;
		}
	}
	
}

function checkWave(mes,ob)
{
	var i=0;
	var n=ob.value;
	var len=n.length;
	
	var j;
	var flag;
	i=0;
	while(i<len)
	{
			flag=0;
			for(j=0;j<10;j++)
			{
				if(n.charAt(i)==j || n.charAt(i)=="-")
				{
					flag=1;
				}
			}
			if(flag==0)
			{
				ob.focus();
				alert(mes);
				return false;
			}
			i=i+1;
	}
}


function checkRange(mes,ob)
{
	var i=0;
	var n=ob.value;
	var len=n.length;
	
	var j;
	var flag;
	i=0;
	while(i<len)
	{
			flag=0;
			for(j=0;j<10;j++)
			{
				if(n.charAt(i)==j || n.charAt(i)=="-" || n.charAt(i)=="'")
				{
					flag=1;
				}
			}
			if(flag==0)
			{
				ob.focus();
				alert(mes);
				return false;
			}
			i=i+1;
	}
}



function checkPassword(mes,ob1,ob2)
{
		if(ob1.value!=ob2.value)
		{
			ob2.focus();
			alert(mes);
			return false;
		}
}
function ParseDate(S) { // Permit ISO DateSeps
return new Date( S.replace(/-/g, "/") ) 
}

function DiffDays(S1, S2) { // ISO date strings
var X = ReadISO8601date(S1) ; if (X<0) return 'Date 1 bad'
var Y = ReadISO8601date(S2) ; if (Y<0) return 'Date 2 bad'
var Dx = Date.UTC(X[0], X[1]-1, X[2])
var Dy = Date.UTC(Y[0], Y[1]-1, Y[2])
return (Dx-Dy)/864e5 
}


function DaysDiff(D1, D2) 
{ // Date Objects, with similar times
return Math.round((D1-D2)/864e5) 
}

function imgFilter(mes,ob)
{
	var file=ob.value;
	var mytool_array=file.split(".");	
	if(file!="")
	{
		if ((mytool_array[mytool_array.length-1].toLowerCase()!="jpg") && (mytool_array[mytool_array.length-1].toLowerCase()!="gif") && (mytool_array[mytool_array.length-1].toLowerCase()!="png"))
		{			
			alert(mes);
			ob.focus();
			return false;
		}
	}
}

	

function checkSize(mes,ob)
{
		if(ob.value.length<6)
		{
				ob.focus();
				alert(mes);
				return false;
		}
}


function validateboard()
{	
	
	flag=checkBlankacc("Please select category type",document.form1.cat_id);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the board title.",document.form1.board_title);
	if(flag==false) { return false; }
	
	//flag=checkBlank("Please enter the board dimension",document.form1.board_dimension);
	//if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the board range",document.form1.board_range);
	if(flag==false) { return false; }
	
	flag=checkRange("Please enter the board range in valid format.",document.form1.board_range);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the board wave size",document.form1.board_wave);
	if(flag==false) { return false; }
	
	flag=checkWave("Please enter the board wave size in valid format",document.form1.board_wave);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the board ability.",document.form1.board_ability);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the board tail.",document.form1.board_tail);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the board price.",document.form1.board_price);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the board price.",document.form1.board_price);
	if(flag==false) { return false; }
	
	flag=checkNumber("Please enter the board price in valid format.",document.form1.board_price);
	if(flag==false) { return false; }
	
	
	//flag=checkBlank("Please enter the board image1.",document.form1.board_image1);
	//if(flag==false) { return false; }
	
	flag=imgFilter("Upload board image1 in .jpg  or .gif or .png  format only.",document.form1.board_image1);
	if(flag==false) { return false; }
	
	//flag=checkBlank("Please enter the board image2.",document.form1.board_image2);
	//if(flag==false) { return false; }
	
	
	
	flag=imgFilter("Upload board image1 in .jpg  or .gif or .png  format only.",document.form1.board_image2);
	if(flag==false) { return false; }
	
	
}

function editboard()
{	
	
	flag=checkBlankacc("Please select category type",document.form1.cat_id);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the board title.",document.form1.board_title);
	if(flag==false) { return false; }
	
	
	//flag=checkBlank("Please enter the board dimension",document.form1.board_dimension);
	//if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the board range",document.form1.board_range);
	if(flag==false) { return false; }
	
	flag=checkRange("Please enter the board range in valid format.",document.form1.board_range);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the board wave size",document.form1.board_wave);
	if(flag==false) { return false; }
	
	flag=checkWave("Please enter the board wave size in valid format",document.form1.board_wave);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the board ability.",document.form1.board_ability);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the board tail.",document.form1.board_tail);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the board price.",document.form1.board_price);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the board price.",document.form1.board_price);
	if(flag==false) { return false; }
	
	flag=checkNumber("Please enter the board price in valid format.",document.form1.board_price);
	if(flag==false) { return false; }
	
	
	
	
	flag=imgFilter("Upload board image1 in .jpg  or .gif or .png  format only.",document.form1.board_image1);
	if(flag==false) { return false; }
	
	
	
	
	
	flag=imgFilter("Upload board image1 in .jpg  or .gif or .png  format only.",document.form1.board_image2);
	if(flag==false) { return false; }
	
	
}
function validate_login()
{
	flag=checkBlank("Please enter the user Name",document.form1.user_name);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the Password",document.form1.user_password);
	if(flag==false) { return false; }
}


function validateteam()
{	
	
	flag=checkBlank("Please enter surfer name",document.form1.team_name);
	if(flag==false) { return false; }

	flag=checkBlank("Please enter surfer born date",document.form1.team_born);
	if(flag==false) { return false; }
	
	flag=checkDate("Please enter surfer born date in format dd/mm/yyyy",document.form1.team_born);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter surfer thumbnail image",document.form1.team_thumbnail_image);
	if(flag==false) { return false; }

	flag=imgFilter("Upload thumbnail image in .jpg or .JPG or .gif or .png  format only.",document.form1.team_thumbnail_image);
	if(flag==false) { return false; }
	
	if(document.form1.feature_surfer.checked==true)
	{
		flag=checkBlank("Please enter surfer url",document.form1.url);
		if(flag==false) { return false; }
	
		flag=checkBlank("Please enter surfer image",document.form1.team_image);
		if(flag==false) { return false; }
	
		flag=imgFilter("Upload board image in .jpg or .JPG or .gif or .png  format only.",document.form1.team_image);
		if(flag==false) { return false; }
	}
}


function validateteamname()
{	
	flag=checkBlank("Please enter team name",document.form1.team_name);
	if(flag==false) { return false; }
	
	//flag=checkBlank("Please enter team image",document.form1.team_image);
	//if(flag==false) { return false; }
	
	flag=imgFilter("Upload board image1 in .jpg or .JPG or .gif or .png  format only.",document.form1.team_image);
	if(flag==false) { return false; }
	
}

function validateNews()
{	
	flag=checkBlank("Please enter news title",document.form1.news_title);
	if(flag==false) { return false; }

	flag=checkBlank("Please enter news date",document.form1.news_date);
	if(flag==false) { return false; }
	
	flag=imgFilter("Upload news image1 in .jpg or .JPG or .gif or .png  format only.",document.form1.news_image);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter news description.",document.form1.news_desc);
	if(flag==false) { return false; }
}

function validateteamedit()
{	
	flag=checkBlank("Please enter surfer name",document.form1.team_name);
	if(flag==false) { return false; }

	flag=checkBlank("Please enter surfer born date",document.form1.team_born);
	if(flag==false) { return false; }
	
	flag=checkDate("Please enter surfer born date in format dd/mm/yyyy",document.form1.team_born);
	if(flag==false) { return false; }
		
	if(document.form1.feature_surfer.checked==true)
	{
		flag=checkBlank("Please enter surfer url",document.form1.url);
		if(flag==false) { return false; }
	
		//flag=checkBlank("Please enter surfer image",document.form1.team_image);
		//if(flag==false) { return false; }
	
		flag=imgFilter("Upload board image1 in .jpg or .JPG or .gif or .png  format only.",document.form1.team_image);
		if(flag==false) { return false; }
	}
	
}


function validatecategory()
{
	flag=checkBlank("Please enter category name",document.form1.cat_name);
	if(flag==false) { return false; }
}

function validateteamgallery()
{
	
	flag=checkBlankacc("Please select surfer name",document.form1.team_id);
	if(flag==false) { return false; }
	
	
	
	/*flag=checkBlank("Please enter gallery image1",document.form1.team_gallery_image1);
	if(flag==false) { return false; }
	
	flag=imgFilter("Upload image1 in .jpg  or .gif or .png  format only.",document.form1.team_image1);
	if(flag==false) { return false; }
	
	flag=imgFilter("Upload image2 in .jpg  or .gif or .png  format only.",document.form1.team_image2);
	if(flag==false) { return false; }
	
	flag=imgFilter("Upload image3 in .jpg  or .gif or .png  format only.",document.form1.team_image3);
	if(flag==false) { return false; }
	
	flag=imgFilter("Upload image4 in .jpg  or .gif or .png  format only.",document.form1.team_image4);
	if(flag==false) { return false; }
	
	flag=imgFilter("Upload image5 in .jpg  or .gif or .png  format only.",document.form1.team_image5);
	if(flag==false) { return false; }
*/
}


function validateclothinggallery()
{
	
	flag=checkBlankacc("Please select clothing name",document.form1.clothing_id);
	if(flag==false) { return false; }

}

function validateclothing()
{
	flag=checkBlank("Please enter clothing name",document.form1.clothing_name);
	if(flag==false) { return false; }	
}

function validategallery()
{
	flag=checkBlank("Please enter gallery name",document.form1.gallery_name_id);
	if(flag==false) { return false; }	
}


function validateorder()
{	
	
	flag=checkBlank("Please enter the user name.",document.form1.order_username);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the user height.",document.form1.order_userheight);
	if(flag==false) { return false; }
	
	//flag=checkRange("Please enter the user height in valid format.",document.form1.order_userheight);
	//if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the user weight.",document.form1.order_userweight);
	if(flag==false) { return false; }
	
	//flag=checkNumber("Please enter the user weight in valid format.",document.form1.order_userweight);
	//if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the user email.",document.form1.order_useremail);
	if(flag==false) { return false; }
	
	flag=checkEmail("Please enter the user email address in valid format.",document.form1.order_useremail);
	if(flag==false) { return false; }
	
	
	flag=checkBlank("Please enter the user telephone number.",document.form1.order_usertelno);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the  boardmodel.",document.form1.order_boardmodel);
	if(flag==false) { return false; }
	
	//flag=checkBlank("Please enter the boarddimension.",document.form1.order_boarddimension);
	//if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the board length.",document.form1.board_length);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the board width.",document.form1.board_width);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the board depth.",document.form1.board_depth);
	if(flag==false) { return false; }
	
	
	
	
}

function validatepassword()
{
	flag=checkBlank("Please enter the user Name",document.form1.user_name);
	if(flag==false) { return false; }
	
	flag=checkBlank("Please enter the Email.",document.form1.user_email);
	if(flag==false) { return false; }
	
	flag=checkEmail("Please enter  valid Email. ",document.form1.user_email);
	if(flag==false) { return false; }
}

function checkblank(msg,obj)
{
	if(obj.value == "")
		{
		alert(msg);
		obj.focus();
		return false ;
		}
}
function check_length(msg ,obj)
{
	var len;
	n=obj.value;
	len=n.length;
	if(!(len>=4&&len<=15))
		{
			obj.focus();
			alert(msg);
			return false;
		}
}

function check_rpassward(msg,obj1,obj2)
{
    var len1,len2;
	var passward = new Array();
	var rpassward = new Array();
	
	n1=obj1.value;
	lenpass=n1.length;
	passward = n1;
	
	n2=obj2.value;
	lenrpass=n2.length;
	rpassward=n2;
	if(n1 != n2)
		{
		obj2.focus();
		alert(msg);
		return false;
		}
	
}


function checkValid()
{
    var flag;
	flag = checkblank("Please enter user old password!",document.frm1.old);
	if(flag==false) { return false; }
	flag = checkblank("Please enter user new password!",document.frm1.newp);
	if(flag==false) { return false; }
	flag = check_length("Passward should be between 4 to 15 characters long!",document.frm1.newp);
	if(flag==false) { return false; }
	flag = checkblank("Please enter re-enter new password!",document.frm1.con_new);
	if(flag==false) { return false; }
	flag = check_rpassward("Please enter correct passward!",document.frm1.newp,document.frm1.con_new);
	if(flag==false) { return false; }
	
}



function validate()
{
	if(document.form1.email_address.value == "")
		{
		alert("Please enter email address!");
		document.form1.email_address.focus();
		return false ;
		}
	else
	 {	
	flag = check_email("Please enter valid email address!",document.form1.email_address);
			if(flag==false) { return false; }
	 }
}

