// JavaScript Document
function echeck(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1)
	{
		alert("Invalid E-mail ID");
		return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{
		alert("Invalid E-mail ID");
		return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{
		alert("Invalid E-mail ID");
		return false;
	}
	if (str.indexOf(at,(lat+1))!=-1)
	{
		alert("Invalid E-mail ID");
		return false;
    }
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	{
		alert("Invalid E-mail ID");
		return false;
	}
	if (str.indexOf(dot,(lat+2))==-1)
	{
		alert("Invalid E-mail ID");
		return false;
	}
	if (str.indexOf(" ")!=-1)
	{
		 alert("Invalid E-mail ID");
		 return false;
	}
	return true					
}

function emailCheck (emailStr) 
{
	/* The following pattern is used to check if the entered e-mail address
    fits the user@domain format.  It also is used to separate the username
    from the domain. */
	var emailPat=/^(.+)@(.+)$/;
	/* The following string represents the pattern for matching all special
    characters.  We don't want to allow special characters in the address. 
    These characters include ( ) < @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	/* The following string represents the range of characters allowed in a 
    username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]";
	/* The following pattern applies if the "user" is a quoted string (in
    which case, there are no rules about which characters are allowed
    and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
    is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")";
	/* The following pattern applies for domains that are IP addresses,
    rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
    e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	/* The following string represents an atom (basically a series of
    non-special characters.) */
	var atom=validChars + '+';
	/* The following string represents one word in the typical username.
    For example, in john.doe@somewhere.com, john and doe are words.
    Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")";
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	/* The following pattern describes the structure of a normal symbolic
    domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	
	/* Finally, let's start trying to figure out if the supplied address is
    valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
    different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat);
	if (matchArray==null)  
	{
		/* Too many/few @'s or something; basically, this address doesn't
    	even fit the general mould of a valid e-mail address. */
		alert("Email address seems incorrect (check @ and .'s)");
		document.getElementById("email").value = "";
		document.getElementById("email").focus();
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	
	// See if "user" is valid 
	if (user.match(userPat)==null) 
	{
		// user is not valid
		alert("The part of your email address before the '@' doesn't seem to be valid. Please re-type email address again.");
		document.getElementById("email").value = "";
		document.getElementById("email").focus();
		return false;
	}
	
	/* if the e-mail address is at an IP address (as opposed to a symbolic
    host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) 
	{
		// this is an IP address
		for (var i=1;i<=4;i++) 
		{
			if (IPArray[i]>255) 
			{
				alert("Destination IP address is invalid!");
				document.getElementById("email").value = "";
				document.getElementById("email").focus();
				return false;
	        }
		}
    	return true
	}

	// Domain is symbolic name
	var domainArray=domain.match(domainPat);
	if (domainArray==null) 
	{
		alert("Part of your email address after the '@' doesn't seem to be valid. Please enter email again.");
		document.getElementById("email").value = "";
		document.getElementById("email").focus();
    	return false;
	}

	/* domain name seems valid, but now make sure that it ends in a
    three-letter word (like com, edu, gov) or a two-letter word,
    representing country (uk, nl), and that there's a hostname preceding 
    the domain or country. */
	
	/* Now we need to break up the domain to get a count of how many atoms
    it consists of. */
	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>6) 
	{
		// the address must end in a two letter or other TLD including museum
		alert("The address must end in a top level domain (e.g. .com), or two letter country. Please enter again.");
		document.getElementById("email").value = "";
		document.getElementById("email").focus();
		return false;
	}

	// Make sure there's a host name preceding the domain.
	if (len<2) 
	{
		var errStr="This address is missing a hostname! Please try again";
		alert(errStr);
		document.getElementById("email").value = "";
		document.getElementById("email").focus();
		return false;
	}

	// If we've got this far, everything's valid!
	return true;
}

function isPhone(str)
{
	var validchars = "+0123456789";
	var strChars;
	if(str.length == '0') return false;
		
	for(i=0;i<str.length;i++){
		strChars = str.charAt(i);
		if(validchars.indexOf(strChars) == -1) return false;
	}
	return true;
}

function isAlpha(str)
{
	var validchars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
	var strChars;
	var firstchar = ' ';
	if(str.length == '0') return false;
	if(str.charAt(0) == firstchar) return false;
	
	for(i=0;i<str.length;i++){
		strChars = str.charAt(i);
		if(validchars.indexOf(strChars) == -1) return false;
	}
	return true;
}

function isAlphaNumeric(str)
{
	var validchars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
	var strChars;
	var firstchar = ' ';
	if(str.length == '0') return false;
	if(str.charAt(0) == firstchar) return false;
	
	for(i=0;i<str.length;i++){
		strChars = str.charAt(i);
		if(validchars.indexOf(strChars) == -1) return false;
	}
	return true;
}

function isNumeric(str)
{
	var validchars = "0123456789";
	var strChars;
	if(str.length == '0') return false;
	
	for(i=0;i<str.length;i++){
		strChars = str.charAt(i);
		if(validchars.indexOf(strChars) == -1) return false;
	}
	return true;
}

function isheight(str)
{
	var validchars = "0123456789'";
	var strChars;
	if(str.length == '0') return false;
	
	for(i=0;i<str.length;i++){
		strChars = str.charAt(i);
		if(validchars.indexOf(strChars) == -1) return false;
	}
	return true;
}

function isDate(str)
{
	var validchars = "0123456789/";
	var strChars;
	if(str.length == '0') return false;
	
	for(i=0;i<str.length;i++){
		strChars = str.charAt(i);
		if(validchars.indexOf(strChars) == -1) return false;
	}
	return true;
}

function chkform()
{
	if(document.getElementById("regyes").checked == false && document.getElementById("regno").checked == false)
	{
		alert("Please specify are you already registered with caprice or not.");
		document.getElementById("regyes").focus();
		return false;
	}
	if(!isAlpha(document.getElementById("name").value))
	{
		alert("Please enter your full name (alphabets only).");
		document.getElementById("name").value = "";
		document.getElementById("name").focus();
		return false;
	}
	if(document.getElementById("dobday").value == "0")
	{
		alert("Please select day.");
		document.getElementById("dobday").focus();
		return false;
	}
	if(document.getElementById("dobmonth").value == "0")
	{
		alert("Please select month.");
		document.getElementById("dobmonth").focus();
		return false;
	}
	if(document.getElementById("dobyear").value == "0")
	{
		alert("Please select year.");
		document.getElementById("dobyear").focus();
		return false;
	}
	if(!isNumeric(document.getElementById("age").value))
	{
		alert("Please enter your age (numerics only).");
		document.getElementById("age").value = "";
		document.getElementById("age").focus();
		return false;
	}
	if(document.getElementById("home_phone").value != "")
	{
		if(!isNumeric(document.getElementById("home_phone").value))
		{
			alert("Please enter a valid phone number (numerics only).");
			document.getElementById("home_phone").value = "";
			document.getElementById("home_phone").focus();
			return false;
		}
	}
	if(!isNumeric(document.getElementById("mobile").value))
	{
		alert("Please enter a valid mobile number (numerics only).");
		document.getElementById("mobile").value = "";
		document.getElementById("mobile").focus();
		return false;
	}
	if(!emailCheck(document.getElementById("email").value))
	{
		return false;
	}
	if(!isheight(document.getElementById("height").value))
	{
		alert("Please enter valid height (Format: 0'00')");
		document.getElementById("height").value = "";
		document.getElementById("height").focus();
		return false;
	}
	if(!isAlphaNumeric(document.getElementById("bust_chest").value))
	{
		alert("Please enter your bust/chest size (alpha-numerics only).");
		document.getElementById("bust_chest").value = "";
		document.getElementById("bust_chest").focus();
		return false;
	}
	if(!isNumeric(document.getElementById("waist").value))
	{
		alert("Please enter your waist size (numerics only).");
		document.getElementById("waist").value = "";
		document.getElementById("waist").focus();
		return false;
	}
	if(!isNumeric(document.getElementById("hips").value))
	{
		alert("Please enter your hips size (numerics only).");
		document.getElementById("hips").value = "";
		document.getElementById("hips").focus();
		return false;
	}
	if(document.getElementById("Image_1").value == "")
	{
		alert("Please upload first image.");
		return false;
	}
	if(document.getElementById("agreechk").checked == false)
	{
		alert("Please agree our terms and conditions.");
		return false;
	}
	if(document.getElementById("birth_mark").checked == true && document.getElementById("birth_mark_txt").value == "")
	{
		alert("Please enter where you have a birth mark.");
		document.getElementById("birth_mark_txt").focus();
		return false;
	}
	if(document.getElementById("scars").checked == true && document.getElementById("scars_txt").value == "")
	{
		alert("Please enter where you have scars.");
		document.getElementById("scars_txt").focus();
		return false;
	}
	if(document.getElementById("tattoos").checked == true && document.getElementById("tattoos_txt").value == "")
	{
		alert("Please enter where you have tattoos.");
		document.getElementById("tattoos_txt").focus();
		//alert(document.getElementById("agreechk").value);
		return false;
	}
	if(document.getElementById("web_site_release").checked == true && document.getElementById("web_site_release_txt").value == "")
	{
		alert("Please enter your webs site release.");
		document.getElementById("web_site_release_txt").focus();
		return false;
	}
	if(document.getElementById("portfolio").checked == true && document.getElementById("portfolio_txt").value == "")
	{
		alert("Please enter your portfolio.");
		document.getElementById("portfolio_txt").focus();
		return false;
		
	}
}

function uploadimg_1()
{
	windowURL = "upload_img_1.php";
	window.open( windowURL, 'OpenWinUserContest','width=350,height=150,toolbar=no,location=0,directories=0,status=no,menuBar=0,scrollBars=no,resizable=no,left=350,top=300'); 
}

function uploadimg_2()
{
	windowURL = "upload_img_2.php";
	window.open( windowURL, 'OpenWinUserContest','width=350,height=150,toolbar=no,location=0,directories=0,status=no,menuBar=0,scrollBars=no,resizable=no,left=350,top=300'); 
}

function uploadimg_3()
{
	windowURL = "upload_img_3.php";
	window.open( windowURL, 'OpenWinUserContest','width=350,height=150,toolbar=no,location=0,directories=0,status=no,menuBar=0,scrollBars=no,resizable=no,left=350,top=300'); 
}

function uploadimg_4()
{
	windowURL = "upload_img_4.php";
	window.open( windowURL, 'OpenWinUserContest','width=350,height=150,toolbar=no,location=0,directories=0,status=no,menuBar=0,scrollBars=no,resizable=no,left=350,top=300'); 
}

function uploadimg_5()
{
	windowURL = "upload_img_5.php";
	window.open( windowURL, 'OpenWinUserContest','width=350,height=150,toolbar=no,location=0,directories=0,status=no,menuBar=0,scrollBars=no,resizable=no,left=350,top=300'); 
}

function uploadimg_6()
{
	windowURL = "upload_img_6.php";
	window.open( windowURL, 'OpenWinUserContest','width=350,height=150,toolbar=no,location=0,directories=0,status=no,menuBar=0,scrollBars=no,resizable=no,left=350,top=300'); 
}

function uploadimg_7()
{
	windowURL = "upload_img_7.php";
	window.open( windowURL, 'OpenWinUserContest','width=350,height=150,toolbar=no,location=0,directories=0,status=no,menuBar=0,scrollBars=no,resizable=no,left=350,top=300'); 
}

function uploadimg_8()
{
	windowURL = "upload_img_8.php";
	window.open( windowURL, 'OpenWinUserContest','width=350,height=150,toolbar=no,location=0,directories=0,status=no,menuBar=0,scrollBars=no,resizable=no,left=350,top=300'); 
}
