﻿function CheckPost(arrControlsID)
{
    return(
        
        isBlank("Contest Title",document.getElementById(arrControlsID[0]),document.getElementById(arrControlsID[1])) &&
        
        isBlankDropDownForArtWork("Entry Type",document.getElementById(arrControlsID[2]),document.getElementById(arrControlsID[3])) &&
        
        isBlankDropDownForArtWork("Contest Type",document.getElementById(arrControlsID[4]),document.getElementById(arrControlsID[5])) &&
        
        isBlank("Eligibility",document.getElementById(arrControlsID[6]),document.getElementById(arrControlsID[7])) &&
        
        isBlank("Prize",document.getElementById(arrControlsID[8]),document.getElementById(arrControlsID[9])) &&
        
        isBlankDropDown("Starting Date Month",document.getElementById(arrControlsID[10]),document.getElementById(arrControlsID[13])) &&
        
        isBlankDropDown("Starting Date Day",document.getElementById(arrControlsID[11]),document.getElementById(arrControlsID[13])) &&
        
        isBlankDropDown("Starting Date Year",document.getElementById(arrControlsID[12]),document.getElementById(arrControlsID[13])) &&
        
        isBlankDropDown("End Date Month",document.getElementById(arrControlsID[14]),document.getElementById(arrControlsID[17])) &&
        
        isBlankDropDown("End Date Day",document.getElementById(arrControlsID[15]),document.getElementById(arrControlsID[17])) &&
    
        isBlankDropDown("End Date Year",document.getElementById(arrControlsID[16]),document.getElementById(arrControlsID[17])) &&
        
        isBlank("Contest Information",document.getElementById(arrControlsID[18]),document.getElementById(arrControlsID[19]))
    );
}

function ShowUserNameResults(result)
        {
           var arrControlsId = result.split(',');
          document.getElementById (arrControlsId[1]).innerHTML = arrControlsId[0];
          return false;
        
        }
        
function ShowEmailResults(result)
        {
           var arrControlsId = result.split(',');
          document.getElementById (arrControlsId[1]).innerHTML = arrControlsId[0];
        return false;
        }

function CheckPurchase(arrControlsID)
{
    return(
        isBlank("Your Email Address",document.getElementById(arrControlsID[0]),document.getElementById(arrControlsID[1])) &&
        
        emailCheck(document.getElementById(arrControlsID[0]),document.getElementById(arrControlsID[1]))
    );
}
function ArtworkValidate(arrControlsID)
{
    return (
    
        isBlank("File",document.getElementById(arrControlsID[0]),document.getElementById(arrControlsID[1])) &&
        
        isBlank("Artwork Title",document.getElementById(arrControlsID[2]),document.getElementById(arrControlsID[3])) &&
        
        isBlankDropDownForArtWork("Category",document.getElementById(arrControlsID[4]),document.getElementById(arrControlsID[5])) &&
        
        isBlank("Keywords",document.getElementById(arrControlsID[6]),document.getElementById(arrControlsID[7])) &&

        isValidSalePrice("Sale Price", document.getElementById(arrControlsID[8]), document.getElementById(arrControlsID[10]), document.getElementById(arrControlsID[9])) &&
        
        isNumeric("Sale Price",document.getElementById(arrControlsID[8]),document.getElementById(arrControlsID[9]))
        
        );
}
function ResetPasswordValidation(arrControlsID)
{
    
    return(
    isBlank("Password",document.getElementById(arrControlsID[0]),document.getElementById(arrControlsID[1])) &&
    
    isBlank("Confirm Password",document.getElementById(arrControlsID[2]),document.getElementById(arrControlsID[3])) &&
    
    isEqual("Password",document.getElementById(arrControlsID[0]),"Confirm Password",document.getElementById(arrControlsID[2]),document.getElementById(arrControlsID[3]))
    
    );
}

function PublishSeasonalContestValidation(arrControlsID)
{
    return(
        isBlank("Theme",document.getElementById(arrControlsID[0]),document.getElementById(arrControlsID[1])) &&
        
        isBlank("Duration",document.getElementById(arrControlsID[2]),document.getElementById(arrControlsID[3])) 
        
       
        
        
    );
}
function RegisterOrgValidation(arrControlsID)
{
    return(
        
        
        isBlank("Organization Name",document.getElementById(arrControlsID[0]),document.getElementById(arrControlsID[1])) &&
        
        isBlankDropDownForArtWork("Organization Type",document.getElementById(arrControlsID[3]),document.getElementById(arrControlsID[4])) &&
        
        isBlank("Contact Name",document.getElementById(arrControlsID[5]),document.getElementById(arrControlsID[6])) &&
        isAlphabetic("Contact Name",document.getElementById(arrControlsID[5]),document.getElementById(arrControlsID[6])) &&
        
        isBlank("Contact Email",document.getElementById(arrControlsID[7]),document.getElementById(arrControlsID[8])) &&
        emailCheck(document.getElementById(arrControlsID[7]),document.getElementById(arrControlsID[8])) &&
        
        isBlank("Street Address",document.getElementById(arrControlsID[9]),document.getElementById(arrControlsID[10])) &&
        
        isBlank("Town",document.getElementById(arrControlsID[11]),document.getElementById(arrControlsID[12])) &&
        isAlphabetic("Town",document.getElementById(arrControlsID[11]),document.getElementById(arrControlsID[12])) &&
        
        isBlankDropDownForArtWork("State",document.getElementById(arrControlsID[13]),document.getElementById(arrControlsID[14])) &&
        
        isBlankDropDownForArtWork("Country",document.getElementById(arrControlsID[16]),document.getElementById(arrControlsID[17])) &&
        
        isBlank("UserName",document.getElementById(arrControlsID[18]),document.getElementById(arrControlsID[19])) &&
        
        isBlank("Password",document.getElementById(arrControlsID[20]),document.getElementById(arrControlsID[21])) &&
        
        isBlank("Retype Password",document.getElementById(arrControlsID[22]),document.getElementById(arrControlsID[23]))&&
        isEqual("Password",document.getElementById(arrControlsID[20]),"Retype Password",document.getElementById(arrControlsID[22]),document.getElementById(arrControlsID[23])) &&
        
        isBlank("Organization Email",document.getElementById(arrControlsID[24]),document.getElementById(arrControlsID[25])) &&
        emailCheck(document.getElementById(arrControlsID[24]),document.getElementById(arrControlsID[25]))
        );
}

function Validation() 
         {

           var elementIdList = "ctl00_BodyPlaceHolder_SignUp_txtFName,ctl00_BodyPlaceHolder_SignUp_lblFName,ctl00_BodyPlaceHolder_SignUp_txtLName,ctl00_BodyPlaceHolder_SignUp_lblLName,ctl00_BodyPlaceHolder_SignUp_txtUserName,ctl00_BodyPlaceHolder_SignUp_lblUserName,ctl00_BodyPlaceHolder_SignUp_txtPassword,ctl00_BodyPlaceHolder_SignUp_lblPassword,ctl00_BodyPlaceHolder_SignUp_txtConfirmPassword,ctl00_BodyPlaceHolder_SignUp_lblConfirmPassword,ctl00_BodyPlaceHolder_SignUp_txtEmail,ctl00_BodyPlaceHolder_SignUp_lblEmail,ctl00_BodyPlaceHolder_SignUp_ddlGender,ctl00_BodyPlaceHolder_SignUp_lblGender,ctl00_BodyPlaceHolder_SignUp_ddlDobMonth,ctl00_BodyPlaceHolder_SignUp_ddlDobDay,ctl00_BodyPlaceHolder_SignUp_ddlDobYear,ctl00_BodyPlaceHolder_SignUp_lblBirthDay,ctl00_BodyPlaceHolder_SignUp_agreement,ctl00_BodyPlaceHolder_SignUp_lblAgreement";
           var arrControlsId = elementIdList.split(',');

           //MakeAllLabelVisibleFalse(elementIdList);

         return(
        
            isBlank("First Name", document.getElementById(arrControlsId[0]), document.getElementById(arrControlsId[1]) ) &&
            isAlphabetic("First Name", document.getElementById(arrControlsId[0]), document.getElementById(arrControlsId[1]) ) &&
            
            isBlank("Last Name", document.getElementById(arrControlsId[2]), document.getElementById(arrControlsId[3]) ) &&
            isAlphabetic("Last Name", document.getElementById(arrControlsId[2]), document.getElementById(arrControlsId[3]) ) &&
            
            isBlank("UserName", document.getElementById(arrControlsId[4]), document.getElementById(arrControlsId[5]) ) &&
            CheckLength("UserName", document.getElementById(arrControlsId[4]) , 5, document.getElementById(arrControlsId[5]) ) &&
            isAlphaNumeric("UserName", document.getElementById(arrControlsId[4]), document.getElementById(arrControlsId[5]) ) &&
            
            isBlank("Password", document.getElementById(arrControlsId[6]), document.getElementById(arrControlsId[7]) ) &&
            CheckLength("Password", document.getElementById(arrControlsId[6]) , 6, document.getElementById(arrControlsId[7]) ) &&
            isAlphaNumeric("Password", document.getElementById(arrControlsId[6]), document.getElementById(arrControlsId[7]) ) &&
            
            isBlank("Confirm Password", document.getElementById(arrControlsId[8]), document.getElementById(arrControlsId[9]) ) &&
            CheckLength("Confirm Password", document.getElementById(arrControlsId[8]) , 6, document.getElementById(arrControlsId[9]) ) &&
            isAlphaNumeric("Confirm Password", document.getElementById(arrControlsId[8]), document.getElementById(arrControlsId[9]) ) &&
            isEqual("Password", document.getElementById(arrControlsId[6]) , "Confirm Password", document.getElementById(arrControlsId[8]), document.getElementById(arrControlsId[9]) ) &&
            
            isBlank("Email", document.getElementById(arrControlsId[10]), document.getElementById(arrControlsId[11]) ) &&
            emailCheck(document.getElementById(arrControlsId[10]), document.getElementById(arrControlsId[11]) ) &&
            
            isBlankDropDown("Gender" , document.getElementById(arrControlsId[12]), document.getElementById(arrControlsId[13]) ) &&
            
            isBlankDropDown("Month" , document.getElementById(arrControlsId[14]), document.getElementById(arrControlsId[17]) ) &&
            isBlankDropDown("Day" , document.getElementById(arrControlsId[15]), document.getElementById(arrControlsId[17]) ) &&
            isBlankDropDown("Year" , document.getElementById(arrControlsId[16]), document.getElementById(arrControlsId[17]) ) &&
            
            CallDateFun(document.getElementById(arrControlsId[15]), document.getElementById(arrControlsId[14]), document.getElementById(arrControlsId[16]), document.getElementById(arrControlsId[17]) ) &&
            
            isChecBoxChecked(document.getElementById(arrControlsId[18]), 'Please Accept Term of Service and Policy', document.getElementById(arrControlsId[19]) )
            
            );            

         } 
         
         
         
         function MakeAllLabelVisibleFalse(strScri)
            {
                var arrControlsId =strScri.split(',');
                document.getElementById(arrControlsId[1]).innerHTML = "";
                document.getElementById(arrControlsId[3]).innerHTML = "";
                document.getElementById(arrControlsId[5]).innerHTML = "";
                document.getElementById(arrControlsId[7]).innerHTML = "";
                document.getElementById(arrControlsId[9]).innerHTML = "";
                document.getElementById(arrControlsId[11]).innerHTML = "";
                document.getElementById(arrControlsId[13]).innerHTML = "";
                document.getElementById(arrControlsId[17]).innerHTML = "";
                document.getElementById(arrControlsId[19]).innerHTML = "";
               
            }
            
            function LoginValidation(arrControlsId) 
             { 
             
               return(
           
                isBlankLogin("Username", document.getElementById(arrControlsId[0]), document.getElementById(arrControlsId[2]) ) &&
               
                
                isBlankLogin("Password", document.getElementById(arrControlsId[1]), document.getElementById(arrControlsId[2]) )
              
                
            );
            

         } 
         

function isLessThanOrEqual(ElementName,ElementValue,Value,Message)
{
    if(ElementValue.value<1 || ElementValue.value>Value)
    {
        Message.innerHTML='Value of '+ElementName+' should be between 1 and 12.';
        ElementValue.focus();
        return false;
    }
    return true;
}         

function CheckLength(ElementName, ElementValue, len, Message)
    {
        
        if(ElementValue.value.length < len) 
        {

            Message.innerHTML = 'Sorry! ' + ElementName + ' should be of minimum ' + len + ' Characters.';
            ElementValue.focus();
            return false;
        }
       
        return true;
       
    }
    

function isBlankLogin(ElementName, ElementValue, Message)
    {
        
        
        if(ElementValue.value != '')
        {
            Message.innerHTML="";
            return true;
        }

        Message.innerHTML = "Please enter " + ElementName + ".";
        ElementValue.focus();
        return false;
       
    }

    function isValidSalePrice(ElementName, ElementValue, TriggerElement, Message) {
        
        myradioList = document.getElementsByName(TriggerElement.id.replace(/_/g, '$'));
        for (var i = 0; i < myradioList.length; i++) {
            if (myradioList[i].checked == true) {
                if (myradioList[i].value == "1") {
                    return isBlank(ElementName, ElementValue, Message);
                }
                else {
                    return true;
                }                
            }
        }        
    }
    function isBlank(ElementName, ElementValue, Message)
    {   
        if(ElementValue.value != '')
        {
            Message.innerHTML="";
            return true;
        }
        if(Message.textContent)
        {
        //Firefox
            Message.textContent = "Sorry! " + ElementName + " Can Not be Blank";
        }
        else if(Message.innerText)
        {
        //IE
            Message.innerText="Sorry! " + ElementName + " Can Not be Blank";
        }
        else
        {
        //Default
            Message.innerHTML="Sorry! " + ElementName + " Can Not be Blank";
        }
        ElementValue.focus();
        return false;       
    }
    
function isEqual(ElementName1, ElementValue1,ElementName2, ElementValue2, Message) {
if((ElementValue1.value == "") || (ElementValue2.value == "")) return true;	
var msg
if(ElementValue1.value != ElementValue2.value)
{
	msg="The "+ElementName1+" & "+ElementName2+" should be equal. Please check and re-enter."
	Message.innerHTML = msg;
	ElementValue2.focus();
	ElementValue2.select();
	return false;
}
else return true;
}

function isBlankDropDown(ElementName, ElementValue, Message) {

if( ElementValue == false || ElementValue.options[ElementValue.selectedIndex].text == "" )
{

      Message.innerHTML = "Please Select " + ElementName;
      ElementValue.focus();
      return false;
}
else
{
    Message.innerHTML="";
    return true;
}
return true;

}

function isBlankCalender(ElementName, ElementValue, Message) {

if( ElementValue == false || ElementValue.options[ElementValue.selectedDate].text == "" )
{

      Message.innerHTML = "Please Select " + ElementName;
      ElementValue.focus();
      return false;
}
return true;

}

function isBlankDropDownForArtWork(ElementName, ElementValue, Message) {

if( ElementValue == false || ElementValue.options[ElementValue.selectedIndex].text == "" || ElementValue.options[ElementValue.selectedIndex].value == 0 )
{
      Message.innerHTML = "Please Select " + ElementName;
      ElementValue.focus();
      return false;
}
else
{
Message.innerHTML="";
return true;
}

}





function isAlphaNumeric(ElementName, ElementValue, Message) {
var i,s,msg;
var flag=0;
for (i = 0; i < ElementValue.value.length; i++)
{   
	s = ElementValue.value.charAt(i);
	if ( ((s < '0')||(s > '9')) && ((s < 'a')||(s > 'z')) && ((s < 'A')||(s > 'Z')) )
	{
		msg = "Invalid " + ElementName + ". It can contain only [a-z] or [A-Z] or [0-9]. \n Please re-enter the " + ElementName + ".";

        Message.innerHTML = msg;
		ElementValue.focus();
		return false;
	}
}
return true;	
}


function isAlphabetic(ElementName, ElementValue, Message) {
var len= ElementValue.value.length;



var p=0;
var ok= true;
var ch= "";
while (ok && p<len)
{
	ch= ElementValue.value.charAt(p);
    if((('A'<=ch && ch<='Z')||('a'<=ch && ch<='z') || (ch == ' ')))
      p++;
    else
	{
		msg = ElementName + " should contain only alphabets. Please re-enter " + ElementName + "."
		Message.innerHTML = msg;

		ElementValue.focus();
		ok= false;
    }
}
return ok;
}



function isNumeric(ElementName, ElementValue, Message) {
var len= ElementValue.value.length;



var p=0;
var ok= true;
var ch= "";
while (ok && p<len)
{
	ch= ElementValue.value.charAt(p);
    if('0'<=ch && ch<='9')
      p++;
    else
	{
	    if(ElementValue.value=="Contact Artist" || ElementValue.value=="Not for sale")
	    {
	        p++;
	    }
	    else
	    {
	    		msg = ElementName + " should contain only numerics or the text 'Contact Artist' or 'Not for sale'. Please re-enter " + ElementName + "."
		        Message.innerHTML = msg;

		        ElementValue.focus();
		        ok= false;
		 }
    }
}
return ok;
}







function emailCheck (emailStr, Message) {

    /* The following variable tells the rest of the function whether or not
    to verify that the address ends in a two-letter country or well-known
    TLD.  1 means check it, 0 means don't. */

    var checkTLD=1;

    /* The following is the list of known TLDs that an e-mail address must end with. */

    var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

    /* 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.value.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. */


    Message.innerHTML = "Email address seems incorrect (check @ and .'s)";
    return false;
    }
    var user=matchArray[1];
    var domain=matchArray[2];

    // Start by checking that only basic ASCII characters are in the strings (0-127).

    for (i=0; i<user.length; i++) {
    if (user.charCodeAt(i)>127) {

    Message.innerHTML = "Ths username contains invalid characters.";
    return false;
       }
    }
    for (i=0; i<domain.length; i++) {
    if (domain.charCodeAt(i)>127) {

    Message.innerHTML = "Ths domain name contains invalid characters.";
    return false;
       }
    }

    // See if "user" is valid 

    if (user.match(userPat)==null) {

    // user is not valid
      Message.innerHTML = "The username doesn't seem to be valid.";

    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) {
    Message.innerHTML = "Destination IP address is invalid!";

    return false;
       }
    }
    return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {

Message.innerHTML = "The domain name does not seem to be valid.";
return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
Message.innerHTML = "The address must end in a well-known domain or two letter " + "country.";

return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
Message.innerHTML = "This address is missing a hostname!";

return false;
}

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


function isChecBoxChecked(ElementValue, ElementName, Message)
{
    if(ElementValue.checked)
    return true;
    else
    Message.innerHTML = ElementName;

    ElementValue.focus();
    return false;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 )
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(m,d,y,dd,md,yd,Message){
	var daysInMonth = DaysArray(12)
	

	month=parseInt(m)
	day=parseInt(d)
	year=parseInt(y)
	
    

    if(d == "" )
	{
	    Message.innerHTML = "Please Select Date of Birth from the list";

	    dd.focus();
	    return false;
	}
    if(m == "")
	{
	    Message.innerHTML  = "Please Select Date of Birth from the list";

	    md.focus();
	    return false;
	}
    
    if(y == "")
	{
	    Message.innerHTML = "Please Select Date of Birth from the list";

	    yd.focus();
	    return false;
	}
	
	
	
	if (  (month==2 && day>daysInFebruary(year) ) || day > daysInMonth[month] ){
	    
	   	    Message.innerHTML = "Please enter a valid day"
        
		dd.focus();
		return false;
	}

return true
}

function CallDateFun(dd,md,yd,Message){
   var d = dd.value
   var m = md.selectedIndex
   var y = yd.value
   var Message = Message;
   if(isDate(m,d,y,dd,md,yd,Message))
       
        return true;
   else
        return false;
}

 function ArtWorkValid()
{
		if(document.getElementById("ArtWorkUpload").FileName!='')
		{
			if(document.getElementById("ArtTitle").value!='')
			{
				if(document.getElementById("ArtType").value!='')
				{
					if(document.getElementById("Keywords").value!='')
					{
						return true;
					}
					else
					{
						document.getElementById("lblKeywordError").value="Keywords Cannot Be Left Blank";
						return false;
					}
				}
				else
				{
					document.getElementById("lblCatError").value="Please choose a Category";
					return false;
				}
			}
			else
			{
				document.getElementById("lblTitleError").value="Title Cannot Be Left Blank";
				return false;
			}
		}
		else
		{
			document.getElementById("lblTitleError").value="File Has To Be Selected";
			return false;
		}
			
} 						
   