// JavaScript Document
function calldel(m) 
{
  if(!confirm(m))
  {
    return false;
  }
  else
  return true;
}

function admin_validation(){
var txtUsername=document.Login.txtUsername.value;
	 if(txtUsername == "")
			 {
			 alert("User name is empty");
			 document.Login.txtUsername.focus();
			 return false;
			 }
var txtPassword=document.Login.txtPassword.value;
	 if(txtPassword == ""){
			 alert("Password is empty");
			 document.Login.txtPassword.focus();
			 return false;
	}
}

function confirmMsg(msg){
	if(!confirm(msg)){
		return false;

	} else {
		return true;

	}
}

function poplinks(url)
{
	newwindow=window.open(url,'ImageDisplay','height=559,width=600,left=0,top=0,resizable=yes,scrollbars=no');
	if (window.focus) {newwindow.focus()}
}
function popup(url)
{
	newwindow=window.open(url,'ImageDisplay','height=400,width=600,left=0,top=0,resizable=yes,scrollbars=no');
	if (window.focus) {newwindow.focus()}
}
function popservices(url)
{
	newwindow=window.open(url,'ImageDisplay','height=400,width=600,left=0,top=0,resizable=yes,scrollbars=no');
	if (window.focus) {newwindow.focus()}
}

//validation for General Setting

function generalsetting_validate(){
	if (document.form_general.txt_website.value == "") 
		{
			alert ("Please Enter the Website URL.");
			document.form_general.txt_website.focus();
			return false;
		}
		
	if (document.form_general.txt_numrowsadmin.value == "") 
		{
			alert ("Please Enter the number of rows displayed per page in admin panel.");
			document.form_general.txt_numrowsadmin.focus();
			return false;
		}
	recordvalue = document.form_general.txt_numrowsadmin.value;
		if((recordvalue == "")  || (recordvalue == 0) || isNaN(recordvalue) ||  (recordvalue.indexOf("-") >= 0) || (recordvalue.indexOf(".") >= 0) || (recordvalue > 65535) ){
			alert ("Please enter the valid number of rows per page in admin panel.");
			document.form_general.txt_numrowsadmin.focus();
			return false;
		}
	if (document.form_general.txt_numrowsfront.value == "") 
		{
			alert ("Please Enter the number of rows displayed per page in admin panel.");
			document.form_general.txt_numrowsfront.focus();
			return false;
		}
	recordvalue = document.form_general.txt_numrowsfront.value;
		if((recordvalue == "")  || (recordvalue == 0) || isNaN(recordvalue) ||  (recordvalue.indexOf("-") >= 0) || (recordvalue.indexOf(".") >= 0) || (recordvalue > 65535) ){
			alert ("Please enter the valid number of rows per page in admin panel.");
			document.form_general.txt_numrowsfront.focus();
			return false;
		}
	if (document.form_general.txt_admintitle.value == "") 
		{
			alert ("Please enter the admin page title.");
			document.form_general.txt_admintitle.focus();
			return false;
		}
	if (document.form_general.txt_hometitle.value == "") 
		{
			alert ("Please enter the home page title."); 
			document.form_general.txt_hometitle.focus();
			return false;
		}
		if (document.form_general.txt_metakeywords.value == "") 
		{
			alert ("Please enter the Metatag keyword.");
			document.form_general.txt_metakeywords.focus();
			return false;
		}
	if (document.form_general.txt_metadesc.value == "") 
		{
			alert ("Please enter the Metatardescription."); 
			document.form_general.txt_metadesc.focus();
			return false;
		}

}


//Myprofile validation

function myprofile_validate(){
		if (document.frm_myprofile.txt_company.value == "") 
		{
			alert ("Please enter the company / store name.");
			document.frm_myprofile.txt_company.focus();
			return false;
		}
		if (document.frm_myprofile.txt_contactperson.value == "") 
		{
			alert ("Please Enter the Contact Person name.");
			document.frm_myprofile.txt_contactperson.focus();
			return false;
		}
		var emailid = document.frm_myprofile.txt_email.value;
		if(emailid == "")
		{
		alert("Please enter the Email address");
		document.frm_myprofile.txt_email.focus();
		return false;		
		}	
		
		if (!validateEmail(emailid,1,1)) 
		{
		document.frm_myprofile.txt_email.focus();
		return false;
		}			
		
		if (document.frm_myprofile.txt_phone.value == "") 
		{
			alert ("Please Enter the Phone Number.");
			document.frm_myprofile.txt_phone.focus();
			return false;
		}
		phone = document.frm_myprofile.txt_phone;
		if (checkInternationalPhone(phone.value)==false){
			alert("Please Enter a Valid Phone Number")
			phone.value=""
			phone.focus()
			return false
			}
		if (document.frm_myprofile.txt_username.value == "") 
		{
			alert ("Please Enter the User Name.");
			document.frm_myprofile.txt_username.focus();
			return false;
		}
		if (document.frm_myprofile.txt_password.value == "") 
		{
			alert ("Please Enter the Password.");
			document.frm_myprofile.txt_password.focus();
			return false;
		}
}

//Email Validation Script

function validateEmail(addr,man,db) {
	if (addr == '' && man) {
	   if (db) alert('Email address is mandatory');
	   return false;
	}
	var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
	for (i=0; i<invalidChars.length; i++) {
	   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
		  if (db) alert('Email address contains invalid characters');
		  return false;
	   }
	}
	for (i=0; i<addr.length; i++) {
	   if (addr.charCodeAt(i)>127) {
		  if (db) alert("Email address contains non ascii characters.");
		  return false;
	   }
	}

	var atPos = addr.indexOf('@',0);
	if (atPos == -1) {
	   if (db) alert('Email address must contain an @');
	   return false;
	}
	if (atPos == 0) {
	   if (db) alert('Email address must not start with @');
	   return false;
	}
	if (addr.indexOf('@', atPos + 1) > - 1) {
	   if (db) alert('Email address must contain only one @');
	   return false;
	}
	if (addr.indexOf('.', atPos) == -1) {
	   if (db) alert('Email address must contain a period in the domain name');
	   return false;
	}
	if (addr.indexOf('@.',0) != -1) {
	   if (db) alert('period must not immediately follow @ in email address');
	   return false;
	}
	if (addr.indexOf('.@',0) != -1){
	   if (db) alert('period must not immediately precede @ in email address');
	   return false;
	}
	if (addr.indexOf('..',0) != -1) {
	   if (db) alert('two periods must not be adjacent in email address');
	   return false;
	}
	var suffix = addr.substring(addr.lastIndexOf('.')+1);
	if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
	   if (db) alert('invalid primary domain in email address');
	   return false;
	}
return true;
}

 //Function phone validation Script
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone)
{
	s=stripCharsInBag(strPhone,validWorldPhoneChars);
	return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

//script validation for date 
function date_valid(dateissue,dateissue2){
	var stdate=dateissue.split("/");
	var enddate=dateissue2.split("/");
	var prostdate = new Date();
	prostdate.setFullYear(stdate[2]);
	prostdate.setMonth(stdate[0]-1);
	prostdate.setDate(stdate[1]);
	
	var proenddate = new Date();
	proenddate.setFullYear(enddate[2]);
	proenddate.setMonth(enddate[0]-1);
	proenddate.setDate(enddate[1]);
	
	var startingdate = prostdate.getTime();
	var endingdate = proenddate.getTime();

	if(startingdate > endingdate)
	{
		return false;
	}
	return true;
}



function mailsetting_validate()
{
		if (document.frm_mailsettings.txt_subject.value == "") 
		{
			alert ("Please enter the subject");
			document.frm_mailsettings.txt_subject.focus();
			return false;
		}
		if (document.frm_mailsettings.txt_message.value == "") 
		{
			alert ("Please enter the message");
			document.frm_mailsettings.txt_message.focus();
			return false;
		}
}

//validation for CMS

function CMS_validate(){
		if (document.frmCMS.titletag.value == "") 
		{
			alert ("Please enter the title");
			document.frmCMS.titletag.focus();
			return false;
		}
		if (document.frmCMS.metakeyword.value == "") 
		{
			alert ("Please enter the meta keyword");
			document.frmCMS.metakeyword.focus();
			return false;
		}
		if (document.frmCMS.metadesc.value == "") 
		{
			alert ("Please enter the meta description ");
			document.frmCMS.metadesc.focus();
			return false;
		}
		/*if (document.frm_mailsettings.txt_message.value == "") 
		{
			alert ("Please enter the message");
			document.frm_mailsettings.txt_message.focus();
			return false;
		}*/
}

function innotype_validate(){
		if (document.frmInnovation.txtInnType.value == "") 
		{
			alert ("Please enter the type of innovation");
			document.frmInnovation.txtInnType.focus();
			return false;
		}
}
 


function confirmMsg(msg)
{
	if(!confirm(msg)){
		return false;

	} else {
		return true;

	}
}

//validation for Product

function product_validation(){
		if (document.frmProduct.varProductName.value == "") 
		{
			alert ("Please enter the product name");
			document.frmProduct.varProductName.focus();
			return false;
		}
		if (document.frmProduct.intSalePrice.value == "") 
		{
			alert ("Please enter the price");
			document.frmProduct.intSalePrice.focus();
			return false;
		}
		if (document.frmProduct.varDescLine.value == "") 
		{
			alert ("Please enter the description line");
			document.frmProduct.varDescLine.focus();
			return false;
		}				
		if (document.frmProduct.ThumbnailImage.value == "" && document.frmProduct.ThumbImag.value == "") 
		{
			alert ("Please upload the thumbnail image");
			document.frmProduct.ThumbnailImage.focus();
			return false;
		}
		if (document.frmProduct.MediumImage.value == "" && document.frmProduct.MediumImage1.value == "") 
		{
			alert ("Please upload the medium image");
			document.frmProduct.ThumbnailImage.focus();
			return false;
		}
		if (document.frmProduct.OriginalImage.value == "" && document.frmProduct.OriginalImage1.value == "") 
		{
			alert ("Please upload the oridinal image");
			document.frmProduct.ThumbnailImage.focus();
			return false;
		}
		//if (document.frmProduct.SamImage1.value == "" && document.frmProduct.SamImage11.value == "") 
//		{
//			alert ("Please upload the sample #1 image");
//			document.frmProduct.ThumbnailImage.focus();
//			return false;
//		}		
//		if (document.frmProduct.varSamDesc1.value == "") 
//		{
//			alert ("Please enter the sample #1 description");
//			document.frmProduct.varSamDesc1.focus();
//			return false;
//		}		
}

