/*function checkemail(mailids)
{        

            var arr = new Array('.com','.net','.org','.biz','.coop','.info','.museum','.name','.pro'
                                    ,'.edu','.gov','.int','.mil','.ac','.ad','.ae','.af','.ag','.ai','.al',
                                    '.am','.an','.ao','.aq','.ar','.as','.at','.au','.aw','.az','.ba','.bb',
                                    '.bd','.be','.bf','.bg','.bh','.bi','.bj','.bm','.bn','.bo','.br','.bs',
                                    '.bt','.bv','.bw','.by','.bz','.ca','.cc','.cd','.cf','.cg','.ch','.ci',
                                    '.ck','.cl','.cm','.cn','.co','.cr','.cu','.cv','.cx','.cy','.cz','.de',
                                    '.dj','.dk','.dm','.do','.dz','.ec','.ee','.eg','.eh','.er','.es','.et',
                                    '.fi','.fj','.fk','.fm','.fo','.fr','.ga','.gd','.ge','.gf','.gg','.gh',
                                    '.gi','.gl','.gm','.gn','.gp','.gq','.gr','.gs','.gt','.gu','.gv','.gy',
                                    '.hk','.hm','.hn','.hr','.ht','.hu','.id','.ie','.il','.im','.in','.io',
                                    '.iq','.ir','.is','.it','.je','.jm','.jo','.jp','.ke','.kg','.kh','.ki',
                                    '.km','.kn','.kp','.kr','.kw','.ky','.kz','.la','.lb','.lc','.li','.lk',
                                    '.lr','.ls','.lt','.lu','.lv','.ly','.ma','.mc','.md','.mg','.mh','.mk',
                                    '.ml','.mm','.mn','.mo','.mp','.mq','.mr','.ms','.mt','.mu','.mv','.mw',
                                    '.mx','.my','.mz','.na','.nc','.ne','.nf','.ng','.ni','.nl','.no','.np',
                                    '.nr','.nu','.nz','.om','.pa','.pe','.pf','.pg','.ph','.pk','.pl','.pm',
                                    '.pn','.pr','.ps','.pt','.pw','.py','.qa','.re','.ro','.rw','.ru','.sa',
                                    '.sb','.sc','.sd','.se','.sg','.sh','.si','.sj','.sk','.sl','.sm','.sn',
                                    '.so','.sr','.st','.sv','.sy','.sz','.tc','.td','.tf','.tg','.th','.tj',
                                    '.tk','.tm','.tn','.to','.tp','.tr','.tt','.tv','.tw','.tz','.ua','.ug',
                                    '.uk','.um','.us','.uy','.uz','.va','.vc','.ve','.vg','.vi','.vn','.vu',
                                    '.ws','.wf','.ye','.yt','.yu','.za','.zm','.zw'); 
            var mai = mailids;
            var val = true;

            var dot = mai.lastIndexOf(".");
            var ext = mai.substring(dot,mai.length);
            var at = mai.indexOf("@");
            var dom = dot - at;
            var sp = mai.indexOf(" ");

            if(dom >= 4 && at >1 && sp == -1)
            {
                    for(var i=0; i<arr.length; i++)
                    {
                        if(ext == arr[i])
                        {
                            val = true;
                            break;
                        } 
                        else
                        {
                            val = false;
                        }
                    }
                    if(val == false)
                    {
                        alert("Your maild "+mai+" is not corrrrect");
                        return false;
                    }
            }
            else
            {
                    alert("Your maild "+mai+" is not correct");
                    return false;
            }
        return true;
                       
}
*/
function checkemail(emailid)
{
	
	//var emailid=document.getElementById("emailid").value;
	//alert(emailid);
	var at="@";
	var dot=".";
	var lat=emailid.indexOf(at);
	var lemailid=emailid.length;
	var ldot=emailid.indexOf(dot);
	

	if(emailid=="")
	{
		alert("Enter your E-mail id. Please provide the correct e-mail id so that we will be able to all communication");
	}

	if(emailid.length > 0) 
	{

		if (lat==-1 || lat==0 || lat==lemailid)
		{
		   	alert("Enter your E-mail id. Please provide the correct e-mail id so that we will be able to all communication");
		   	emailid = "";
		   	
		   	return false;
		}
		if (ldot==-1 || ldot==0 || ldot==lemailid)
		{
		    	alert("Enter your E-mail id. Please provide the correct e-mail id so that we will be able to all communication");
			 emailid = "";
		   	 
		    	return false;
		}
		if (emailid.indexOf(at,(lat+1))!=-1)
		{
		   alert("Enter your E-mail id. Please provide the correct e-mail id so that we will be able to all communication");
			emailid = "";
		    	
		    	return false;
		}

		if (emailid.substring(lat-1,lat)==dot || emailid.substring(lat+1,lat+2)==dot)
		{
		    	alert("Enter your E-mail id. Please provide the correct e-mail id so that we will be able to all communication");
			emailid = "";
		    	
		    	return false;
		}

		if (emailid.indexOf(dot,(lat+2))==-1)
		{
		    	alert("Enter your E-mail id. Please provide the correct e-mail id so that we will be able to all communication");
			 emailid = "";
		    	
		    	return false;
		}

		if (emailid.indexOf(" ")!=-1)
		{
		    	alert("Enter your E-mail id. Please provide the correct e-mail id so that we will be able to all communication");
	         	emailid = "";
		    	
			return false;
		}
			
		return true;
		
	}



}







function submitcomment()
{
          
                var username=trim(document.getElementById("username").value);
                var useremail=trim(document.getElementById("useremail").value);
                var rate=trim(document.getElementById("rate").value);
                var comment=trim(document.getElementById("commentsbox").value);				
                var securitycode=trim(document.getElementById("security_code").value); 
                 
                if(username.length==0)
                {        
                      alert("Please enter your name");
                      document.getElementById('username').focus();
                      return false;
                      
                }
                if(useremail.length>0)
                {         
                       if(!checkemail(useremail))
                       {
                            document.getElementById("useremail").focus(); 
                            return false;
                       }
                       
                }
				if(comment.length>1000)
				{
					  alert("Sorry, our system accepts only 1000 characters. \n If your comments is more than 1000 characters\n please send us your comments by mail to support@atyourprice.in.\n  Sorry for the inconvenience caused to you in this regard");
                      document.getElementById('commentsbox').focus();
                      return false; 
				}
                 if(rate=="")
                {
                      alert("Do you like to rate our services, if so, please do so ");
                      document.getElementById('rate').focus();
                      return false;  
                }
                if(securitycode.length==0)
                {
                      alert("Please enter the given security code");
                      document.getElementById('security_code').focus();
                      return false;  
                }
                else
                {          
                        
						document.frmcomment.submit();
                       
                }   
                
}

function openemail(commentid,email,feedback,name)
{
            
			

        /* window.open('/yourprice/lib/usercomments/openemail.php'
					  +
					  '?eid='
					  +
					  email
					  +
					  '&feed='
					  +
					  feedback
					  +
					  '&commentid='
					  +
					  commentid
					  +
					  '&sname='
					  +
					  name,'height=570,width=796'); */
		
		  // window.open("/yourprice/lib/usercomments/openemail.php","Send Reply","height=350,width=570"); 
    		var win=window.open('/yourprice/lib/usercomments/openemail.php' 
								 +
								  '?eid='
								  +
								  email
								  +
								  '&feed='
								  +
								  feedback
								  +
								  '&commentid='
								  +
								  commentid
								  +
								  '&sname='
								  +
								  name
								  ,'','left=0px, top=0px, width=570px, height=350px, scrollbars=no, status =no, resizable=no');
			


}

function showcomments()
{               

            var nodays=document.getElementById("nodays").value;
            var feed=document.getElementById("feedback").value;
			var status=document.getElementById("status").value;
			//alert(status);
            xajax_showcomments(nodays,feed,status);

}
function sendemail()
{
   
       mail_to=trim(document.getElementById('txtEmailto').value);	   
       mail_from=trim(document.getElementById('txtEmailfrm').value);  
       mail_sub=trim(document.getElementById('txtSub').value);  
       mail_msg=trim(document.getElementById('txtMsg').value);	   
       commentid=trim(document.getElementById('commentid').value);
	   action=trim(document.getElementById('sendmessage').value);
	   uname=trim(document.getElementById('username').value);
	   
	  
	   			if(action=="sendmessage")
				{
					 if(document.getElementById('sentitem').checked==true)
					 {
						 	savevalue="save"
							
					 }else
					 {
						 	savevalue="dontsave"
					 }
				}
                if(mail_to.length<=0 )
                {
                      alert("Please provide to: email id");
                      document.getElementById('txtEmailto').focus();
                      return false;
                }
                else if(mail_from.length<=0)
                {
                      alert("Please provide from: email id");
                      document.getElementById('txtEmailfrm').focus();
                      return false;
                }
                else if(mail_sub.length<=0)
                {
                      alert("Please enter the subject");
                      document.getElementById('txtSub').focus();
                      return false;  
                }
                else if(mail_to.length>0)
                {        
                      
                        if (checkemail(mail_to))
                        {    
							if(action=="sendreply")
							{
                             							
								xajax_sendreply(commentid,mail_to,mail_from,mail_sub,mail_msg,uname);
							}
							else if(action=="sendmessage")
							{
								xajax_sendmessage(mail_to,mail_from,mail_sub,mail_msg,savevalue);
							}
                        }
                }
                  
}

function trim(sString) 
{
            while (sString.substring(0,1) == ' ')
            {
                sString = sString.substring(1, sString.length);
            }
            while (sString.substring(sString.length-1, sString.length) == ' ')
            {
                sString = sString.substring(0,sString.length-1);
                }
        return sString;
}

function deletecomments(commentid)
{               
            if(confirm("Do you really want to delete the comment?"))
            {
               
                xajax_deletecomment(commentid);
				showfeedback() ;
                 
            }


}





function showorder(admin,orderid,email)
{
	
	if(admin != 'off')
	{
	 	xajax_searchuserorder(orderid,email,'A');
	}
 	else
	{
		xajax_searchuserorder(orderid,email);
	}
}
function showfeedback() 
{ 
		var radioobject=document.filterfeedback.condition;
		var feed=document.getElementById("feedback").value;
	    var status=document.getElementById("status").value;
		var option="";
		var startdate="";
		var enddate="";
		var lastcondition="";
		var today="";
			
		var len = document.filterfeedback.condition.length
		
		for (i=0; i <len; i++) 
		{
			if (document.filterfeedback.condition[i].checked) 
			{
				optionvalue = document.filterfeedback.condition[i].value;
				break;
			}
		}
		
				
		
		if(optionvalue=="daterange")
		{
			 startdate=document.getElementById("startdate").value;
			 enddate=document.getElementById("enddate").value;
			// alert(startdate);
			// alert(enddate);
			  //alert(optionvalue);
			 if(trim(startdate)=="")
			 {
				 alert("Please Enter Start Date");
				 document.getElementById("startdate").focus();
				 return false;
		     }
			 if(trim(enddate)=="")
			 {
				 alert("Please Enter End Date");
				 document.getElementById("enddate").focus();
				 return false;
		     }
		}else if(optionvalue=="last")
		{
				lastcondition=document.getElementById("lastcondition").value;
				 // alert(lastcondition);
		}
		xajax_showcomments(feed,status,lastcondition,today,startdate,enddate);
} 

function showfeedbackreply() 
{ 
		var radioobject=document.filterfeedbackreply.condition;
		var adminuser=document.getElementById("adminuser").value;	  
		var option="";
		var startdate="";
		var enddate="";
		var lastcondition="";
		var today="";
			
		var len = document.filterfeedbackreply.condition.length
		
		for (i=0; i <len; i++) 
		{
			if (document.filterfeedbackreply.condition[i].checked) 
			{
				optionvalue = document.filterfeedbackreply.condition[i].value;
				break;
			}
		}
		
				
		
		if(optionvalue=="daterange")
		{
			 startdate=document.getElementById("startdate").value;
			 enddate=document.getElementById("enddate").value;
			// alert(startdate);
			// alert(enddate);
			  //alert(optionvalue);
			 if(trim(startdate)=="")
			 {
				 alert("Please Enter Start Date");
				 document.getElementById("startdate").focus();
				 return false;
		     }
			 if(trim(enddate)=="")
			 {
				 alert("Please Enter End Date");
				 document.getElementById("enddate").focus();
				 return false;
		     }
		}else if(optionvalue=="last")
		{
				lastcondition=document.getElementById("lastcondition").value;
				 // alert(lastcondition);
		}
		xajax_showcommentsreply(adminuser,lastcondition,today,startdate,enddate);
} 


function deletecommentreply(replyid)
{               
            if(confirm("Do you really want to delete the comment?"))
            {
               
                xajax_deletecommentreply(replyid);
				                 
            }
			showfeedbackreply() ;


}


function sendbulkemail()
{
		var radioobject=document.filterusers.condition;
		var option="";
		var startdate="";
		var enddate="";
		var lastcondition="";
		var today="";
		var str="";
		var def="";
		var len = document.filterusers.condition.length
		var mail_sub=trim(document.getElementById('txtSub').value);  
        var mail_msg=trim(document.getElementById('txtMsg').value);	 

		for (i=0; i <len; i++) 
		{
			if (document.filterusers.condition[i].checked) 
			{
				optionvalue = document.filterusers.condition[i].value;
				break;
			}
		}
		
				
		if(optionvalue=="daterange")
		{
			 startdate=document.getElementById("startdate").value;
			 enddate=document.getElementById("enddate").value;
			// alert(startdate);
			// alert(enddate);
			  //alert(optionvalue);
			 if(trim(startdate)=="")
			 {
				 alert("Please enter Start Date");
				 document.getElementById("startdate").focus();
				 return false;
		     }
			 if(trim(enddate)=="")
			 {
				 alert("Please enter End Date");
				 document.getElementById("enddate").focus();
				 return false;
		     }
		}else if(optionvalue=="last")
		{
				lastcondition=document.getElementById("lastcondition").value;
				 // alert(lastcondition);
		}
		else if(optionvalue=="individual")
		{
			if(document.getElementById("txtfrom").value == "")
			{
				 alert("Please enter the Mail To address");
				 document.getElementById("txtfrom").focus();
				 return false;
			}
			else
			{
				mailto = document.getElementById("txtfrom").value;
				
					var temp = new Array();
				    temp = mailto.split(',');
					var i=0;
					for(i=0;i<temp.length;i++)
					{
						
						if(temp[i].length<=0 )
              			{
							  alert("Please enter Mail To ");
							  document.getElementById('txtfrom').focus();
							  return false;
						}else if(!chksendermail(temp[i]))
						{
							   document.getElementById('txtfrom').focus();
							  return false;
							  
						}
						xajax_sendbulkmessage(lastcondition,startdate,enddate,mail_sub,mail_msg,temp[i],"sendmessage",document.getElementById("messagetype").value);
						
					}
			}
		}
		if(optionvalue != "individual")
		{
			xajax_sendbulkmessage(lastcondition,startdate,enddate,mail_sub,mail_msg,str,"sendmessage",document.getElementById("messagetype").value);
		}
		
}


function chksendermail(emailid)
{
	
	//var emailid=document.getElementById("emailid").value;
	//alert(emailid);
	var at="@";
	var dot=".";
	var lat=emailid.indexOf(at);
	var lemailid=emailid.length;
	var ldot=emailid.indexOf(dot);
	

	if(emailid=="")
	{
		alert("Please enter your e-mail id ");
	}

	if(emailid.length > 0) 
	{

		if (lat==-1 || lat==0 || lat==lemailid)
		{
		   	alert("Please enter a valid e-mail id");
		   	emailid = "";
		   	
		   	return false;
		}
		if (ldot==-1 || ldot==0 || ldot==lemailid)
		{
		    	alert("Please enter a valid e-mail id");
			 emailid = "";
		   	 
		    	return false;
		}
		if (emailid.indexOf(at,(lat+1))!=-1)
		{
		   	alert("Please enter a valid e-mail id");
			emailid = "";
		    	
		    	return false;
		}

		if (emailid.substring(lat-1,lat)==dot || emailid.substring(lat+1,lat+2)==dot)
		{
		    	alert("Please enter a valid e-mail id");
			emailid = "";
		    	
		    	return false;
		}

		if (emailid.indexOf(dot,(lat+2))==-1)
		{
		    	alert("Please enter a valid e-mail id");
			 emailid = "";
		    	
		    	return false;
		}

		if (emailid.indexOf(" ")!=-1)
		{
		    	alert("Please enter a valid e-mail id");
	         	emailid = "";
		    	
			return false;
		}
			
		return true;
		
	}
}


function showresourcerequest() 
{ 
		var radioobject=document.filterresource.condition;
		//var feed=document.getElementById("feedback").value;
	    //var status=document.getElementById("status").value;
		var option="";
		var startdate="";
		var enddate="";
		var lastcondition="";
		var today="";
			
		var len = document.filterresource.condition.length
		
		for (i=0; i <len; i++) 
		{
			if (document.filterresource.condition[i].checked) 
			{
				optionvalue = document.filterresource.condition[i].value;
				break;
			}
		}
		
				
		
		if(optionvalue=="daterange")
		{
			 startdate=document.getElementById("startdate").value;
			 enddate=document.getElementById("enddate").value;
			// alert(startdate);
			// alert(enddate);
			  //alert(optionvalue);
			 if(trim(startdate)=="")
			 {
				 alert("Please Enter Start Date");
				 document.getElementById("startdate").focus();
				 return false;
		     }
			 if(trim(enddate)=="")
			 {
				 alert("Please Enter End Date");
				 document.getElementById("enddate").focus();
				 return false;
		     }
		}else if(optionvalue=="last")
		{
				lastcondition=document.getElementById("lastcondition").value;
				 // alert(lastcondition);
		}
		xajax_showresources(lastcondition,today,startdate,enddate);
} 



function deleteresource(resourceid)
{               
            if(confirm("Do you really want to delete the Resource?"))
            {
               
                xajax_deleteresource(resourceid);
				showresourcerequest() ;
                 
            }


}

