// JavaScript Document

/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
 /* -----------------------------Validate Email ---------------------------------*/
 
 
 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					
	}
 
 
 
 /* -----------------------------News & Events ---------------------------------*/
 function validateNewsEvents(){
	 
   if ((document.myForm.title.value==0)||(document.myForm.title.value=="")){
		alert("Please enter news and events title")
		document.myForm.title.focus()
		return false
	 }


 }
 /*-----------------------------------------------------------------------------*/
// email related functions

 function validateThread(){
	 
	  if ((document.myForm.threadTitle.value==0)||(document.myForm.threadTitle.value=="")){
		alert("Please enter thread title")
		document.myForm.threadTitle.focus()
		return false
	 }

	if (((document.myForm.category.value==0)) && (document.myForm.uploaded.value==0)  && (document.myForm.blogVideoUrl.value=="")){
		alert("Please upload picture or select category")
		document.myForm.uploaded.focus()
		return false
	}
 
 if ((document.myForm.uploaded.value==0)  && (document.myForm.blogVideoUrl.value=="")){
	 if ((document.myForm.category.value=="")||(document.myForm.category.value==0)){
		alert("Please select category")
		document.myForm.category.focus()
		return false
	 }
	 if ((document.myForm.product.value=="")||(document.myForm.product.value==0)){
		alert("Please select product")
		document.myForm.product.focus()
		return false
	 }
 }
	//return true
	// if ((document.myForm.thread.value=="")||(document.myForm.thread.value==0)){
//		alert("Please enter thread description!")
//		document.myForm.thread.focus()
//		return false
//	 }


 }
// --------------------------------end of buyer section validation--------------------------------------

// --------------------------------validation for Seller section-----------------------------------------

function validatejudge(){
	 if ((document.skunkForm.name.value==null)||(document.skunkForm.name.value==0)){
		alert("Please enter name !")
		document.skunkForm.name.focus()
		return false
	 }
	 if ((document.skunkForm.login.value==null)||(document.skunkForm.login.value==0)){
		alert("Please enter login !")
		document.skunkForm.login.focus()
		return false
	 }
	  if ((document.skunkForm.password.value==null)||(document.skunkForm.password.value==0)){
		alert("Please enter password !")
		document.skunkForm.password.focus()
		return false
	 }
	 if (document.skunkForm.password.value!=document.skunkForm.repassword.value){
		alert("Password Should be match!")
		document.skunkForm.password.focus()
		return false
	 }
	
	var emailID=document.skunkForm.email
	 if ((emailID.value==null)||(emailID.value=="")){
		alert("Please Enter your Email ID")
		emailID.focus()
		return false
	 }
	if (echeck(emailID.value)==false){
		emailID.value=""
		emailID.focus()
		return false
	}
	 
	 
}


// --------------------------------validation for Seller section-----------------------------------------

function validateSkunk(){
	 if ((document.skunkForm.skunkTitle.value==null)||(document.skunkForm.skunkTitle.value==0)){
		alert("Please enter skunk title !")
		document.skunkForm.skunkTitle.focus()
		return false
	 }
	 /*if ((document.skunkForm.description.value==null)||(document.skunkForm.description.value==0)){
		alert("Please enter skunk Description !")
		document.skunkForm.description.focus()
		return false
	 }*/
}
// --------------------------------validation for Poll-----------------------------------------

function validatePoll(){
	 if ((document.pollForm.question.value==null)||(document.pollForm.question.value==0)){
		alert("Please enter poll question !")
		document.pollForm.question.focus()
		return false
	 }
	  if ((document.pollForm.option1.value==null)||(document.pollForm.option1.value==0)){
		alert("Please enter option 1 !")
		document.pollForm.option1.focus()
		return false
	 }
	  if ((document.pollForm.option2.value==null)||(document.pollForm.option2.value==0)){
		alert("Please enter option 2 !")
		document.pollForm.option2.focus()
		return false
	 }
	  if ((document.pollForm.option3.value==null)||(document.pollForm.option3.value==0)){
		alert("Please enter option 3 !")
		document.pollForm.option3.focus()
		return false
	 }
	  if ((document.pollForm.option4.value==null)||(document.pollForm.option4.value==0)){
		alert("Please enter option 4 !")
		document.pollForm.option4.focus()
		return false
	 }
	 /* if ((document.pollForm.answer.value==null)||(document.pollForm.answer.value==0)){
		alert("Please enter the answer !")
		document.pollForm.answer.focus()
		return false
	 }*/
	if ((document.pollForm.publishingDate.value==null)||(document.pollForm.publishingDate.value==0)){
		alert("Please choose publishing date !")
		document.pollForm.publishingDate.focus()
		return false
	 }
	 if (document.pollForm.publishingDate.value){
		 var cur_dat=new Date();
			curdate=cur_dat.getDate();
			if(curdate<10){
			curdate="0"+curdate;
			}
			curmon=cur_dat.getMonth()+ 1;
			if(curmon<10){
			curmon="0"+curmon;
			}
			curYear=cur_dat.getFullYear();
		var campaignDate=document.pollForm.publishingDate.value;
		var d =document.pollForm.publishingDate.value.split('-');
		publishingDate=d[2];
		publishingMon=d[1];
		publishingYear=d[0];
			if((curYear==publishingYear)){
				if((curmon==publishingMon)){
						if(curdate > publishingDate){
						alert("This is an invalid date. Please select the forthcoming date");
						return false;
					}
				}
			}
			if((curYear==publishingYear)){
				if((curmon>publishingMon)){
						alert("This is an invalid date. Please select the forthcoming date");
						return false;
				}
			}
			
			if((curYear>publishingYear)){
				alert("This is an invalid date. Please select the forthcoming date");
				return false;
			}
		
	 }
}