
function validate_freecoupon(form)
{
	if(trim(form.fullname.value)=="" || trim(form.fullname.value)=="Name")
	{
		alert("Please enter Name");
		form.fullname.focus();
		return false;	
	}
	if(trim(form.email.value)=="" || trim(form.email.value)=="Email Address")
	{
		alert("Please enter email address");
		form.email.focus();
		return false;	
	}
	if(checkEmail(form.email.value)==false)
	{
		alert("Please enter the valid email address");
		form.email.focus();
		return false;
	}	
	if(trim(form.phonenumber.value)=="" || trim(form.phonenumber.value)=="Phone Number")
	{
		alert("Please enter phone number");
		form.phonenumber.focus();
		return false;
	}
	return true;
}

function calcCharLen(sForm, sTextArea, sTextInput, iMaxLimit)
{
	var _oDF        = document.forms[sForm];
	var _oTxtA      = _oDF.elements[sTextArea];
	var _iMaxLength = (!iMaxLimit) ? 200 : iMaxLimit;
	var _iCharLeft  = _oTxtA.value.length;

	_oDF.elements[sTextInput].value = _iCharLeft;

	if(_iCharLeft > _iMaxLength)
	{
		_oTxtA.value = _oTxtA.value.substring(0, _iMaxLength);
		_oDF.elements[sTextInput].value = _iMaxLength;
		alert('You can enter only '+_iMaxLength+' characters.');
	}

	
}
function val_new_request(frm){
if(frm.sup_cat.value=="")
	  {
	   alert("Please select the support category");
	   frm.sup_cat.focus();
		  return false;
	  }
}
function val_submit_request(frm){

 if(frm.sup_cat.value=="")
	  {
	   alert("Please select the support category");
	   frm.sup_cat.focus();
		  return false;
	  }
 
 if(trim(frm.subject.value)=="")
	  {
	   alert("Please enter the subject");
	   frm.subject.focus();
		  return false;
	  }
if(trim(frm.comments.value)=="")
	  {
	   alert("Please enter the comments");
	   frm.comments.focus();
		  return false;
	  }


}
function validate_siteconfig(frm)
{ 
	 if(trim(frm.name.value)=="")
	  {
	   alert("Please enter the name ");
	   frm.name.focus();
	   return false;
	  }
	  
	isnum= isNaN(trim(frm.name.value))
	  if(isnum!=true)
	  {
	  alert("Only numeric values are not accepted");
	   frm.name.focus();
	   return false;
	  }
	  
	
	  if(trim(frm.url.value)=="")
	  {
	   alert("Please enter the URL ");
	   frm.url.focus();
		  return false;
	  }
	 // alert(checkDomain(trim(frm.url.value)))
	  if(checkDomain(trim(frm.url.value))==false)
	  {
	   frm.url.focus();
		  return false;
	  }
	  /*if(!isUrl(trim(frm.url.value)))
	 {
		alert("Please enter a valid url");
	   frm.url.focus();
		  return false;
	  }*/
	
	ae =trim(frm.admin_email.value);
	sae =trim(frm.sales_email.value);
	sue =trim(frm.support_email.value);
	  

	 if(trim(frm.admin_email.value)=="")
	  {
	   alert("Please enter the admin email address");
	   frm.admin_email.focus();
		  return false;
	  }
		 if(checkEmail(ae)==false)
		{
			   alert("Please enter a valid admin email address");
			   frm.admin_email.focus();
				  return false;
		}
 
		  if(trim(frm.sales_email.value)=="")
		  {
		   alert("Please enter the sales email address");
		   frm.sales_email.focus();
			  return false;
		  }
		   if(checkEmail(sae)==false)
		{
			   alert("Please enter a valid sales email address");
			   frm.sales_email.focus();
				  return false;
		}
		   if(trim(frm.support_email.value)=="")
		  {
		   alert("Please enter the support email address");
		   frm.support_email.focus();
			  return false;
		  }
		    if(checkEmail(sue)==false)
		{
			   alert("Please enter a valid support email address");
			   frm.support_email.focus();
				  return false;
		}
		////
		  if(trim(frm.testimonial_email.value)=="")
		  {
		   alert("Please enter the testimonial  email address");
		   frm.testimonial_email.focus();
			  return false;
		  }
		    if(checkEmail(trim(frm.testimonial_email.value))==false)
		{
			   alert("Please enter a valid testimonial email address");
			   frm.testimonial_email.focus();
				  return false;
		}
		////
		  if(trim(frm.contactus_email.value)=="")
		  {
		   alert("Please enter the contactus  email address");
		   frm.contactus_email.focus();
			  return false;
		  }
		    if(checkEmail(trim(frm.contactus_email.value))==false)
		{
			   alert("Please enter a valid contactus email address");
			   frm.contactus_email.focus();
				  return false;
		}
		
		///
		
  		 if(trim(frm.order_track.value)=="")
		  {
		   alert("Please enter the order track ID");
		   frm.order_track.focus();
			  return false;
		  }

return true;
}




function validate_editprosec(frm)
{
		if(trim(frm.sec_name.value)=="")
		{
		alert("Please enter the section name");
		frm.sec_name.focus();
		return false;
		}
return true;
}

function validate_addsec(frm)
{
		if(trim(frm.sec_name.value)=="")
		{
		alert("Please enter the section name");
		frm.sec_name.focus();
		return false;
		}
return true;
}



function validate_changepassword(frm)
{
	if(trim(frm.opassword.value)=="")
	{
		alert("Please enter the old password");
		frm.opassword.focus();
		return false;
	}
	
	if(trim(frm.npassword.value)=="")
	{
		alert("Please enter the new password");
		frm.npassword.focus();
		return false;
	}
	
	if(frm.npassword.value.length<6)
	{
		alert("Please enter atleast 6 characters for new password");
		frm.npassword.focus();
		return false;
	}
	
		if(trim(frm.npassword.value)=="")
	{
		alert("Please enter the password");
		frm.npassword.focus();
		return false;
	}
			if(trim(frm.cpassword.value)=="")
	{
		alert("Please confirm the password");
		frm.cpassword.focus();
		return false;
	}
	
	
		if(trim(frm.npassword.value)!=trim(frm.cpassword.value))
	{
		alert("Confirm password must be same as new password");
		frm.cpassword.select();
		return false;
	}

return true;
}



function validate_shipcost(frm)
{
	if(trim(frm.first_item.value)=="")
	{
	  alert(" Please enter first item Cost ");
	  frm.first_item.focus();
	  return false;
	}
	if(isNaN(trim(frm.first_item.value)))
	{
	  alert(" Please enter only numeric values in the first item cost field");
	  frm.first_item.focus();
	  return false;
	}
	
	if(trim(frm.additonal_item.value)=="")
	{
	  alert(" Please enter the extra items cost");
	  frm.additonal_item.focus();
	  return false;
	}
	
	if(isNaN(trim(frm.additonal_item.value)))
	{
	  alert(" Please enter only numeric values in the extra items cost field");
	  frm.additonal_item.focus();
	  return false;
	}
return true;
}



function validate_addman(frm)
{
	if(trim(frm.m_name.value)=="")
	{
	alert(" Please enter the manufacturer name");
	frm.m_name.focus();
	return false;
	}
	if(trim(frm.m_desc.value)=="")
	{
	alert("Please enter the description ");
	frm.m_desc.focus();
	return false;
	}

	if(trim(frm.image.value)=="")
	{
	alert("Please select a manufacturer image");
	frm.image.focus();
	return false;
	}
imagepath= trim(frm.image.value);
if(checkFileType(imagepath)!=true)
{
alert("Please select images of types .jpg, .png and .gif only");
frm.image.select();
return false;

}	
	
return true;
}

function validate_addcat(frm)
{/*
	if(trim(frm.cat_name.value)=="")
	{
	alert("Please enter the category name");
	frm.cat_name.focus();
	return false;
	}
	
	if(trim(frm.image1.value)!="")
	{
	alert("Please select  the category image ");
	frm.cat_name.focus();
	return false;
	}
	imagepath= trim(frm.image1.value);
		if(checkFileType(imagepath)!=true)
		{
		alert("Please select images of types .jpg, .png and .gif only");
		frm.image1.select();
		return false;
		}
	
	if(trim(frm.image2.value)!="")
	{
	alert("Please select  the category watch image ");
	frm.cat_name.focus();
	return false;
	}
	imagepath= trim(frm.image2.value);
		if(checkFileType(imagepath)!=true)
		{
		alert("Please select images of types .jpg, .png and .gif only");
		frm.image2.select();
		return false;
		}
	

return true;*/
}


function validate_editcat(frm)
{
if(trim(frm.cat_name.value)=="")
{
alert("Please enter the category name");
frm.cat_name.focus();
return false;
}
if(trim(frm.image1.value)!="")
	{
	imagepath= trim(frm.image1.value);
		if(checkFileType(imagepath)!=true)
		{
		alert("Please select images of types .jpg, .png and .gif only");
		frm.image1.select();
		return false;
		}
	}
	if(trim(frm.image2.value)!="")
	{
	imagepath= trim(frm.image2.value);
		if(checkFileType(imagepath)!=true)
		{
		alert("Please select images of types .jpg, .png and .gif only");
		frm.image2.select();
		return false;
		}
	}



return true;
}

function validate_login(frm)
{
	if(trim(frm.username.value)=="")
	{
		alert("Please enter the username");
		frm.username.focus();
		return false;
	}
	if(trim(frm.password.value)=="")
	{
		alert("Please enter the password");
		frm.password.focus();
		return false;
	}

return true;
}

function validate_afflogin(frm)
{
	if(trim(frm.aff_username.value)=="")
	{
		alert("Please enter the userID");
		frm.aff_username.focus();
		return false;
	}
	if(trim(frm.aff_password.value)=="")
	{
		alert("Please enter the password");
		frm.aff_password.focus();
		return false;
	}

return true;
}

/*





*/


function show(winURL)
{
 winFeatures= "height=250,width=480";
 winName="test";
 url = "showimage.php?image="+winURL;
  theWin = window.open(url, winName, winFeatures);
  theWin.focus();
}



////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function trim(str)
{
	
//	checkforspecialchars(str);
   return str.replace(/^\s*|\s*$/g,"");
}

function allDigits(str)
{
	return inValidCharSet(str,"0123456789");
}	
function inValidCharSet(str,charset)
{
	var result = true;
	for (var i=0;i<str.length;i++)
		if (charset.indexOf(str.substr(i,1))<0)
		{
			result = false;
			break;
		}
	return result;
}
/*
function checkEmail(str)
	{

		if((str.indexOf("@")==-1) || (str.indexOf(".")==-1))
		{
			fstr="Please enter @ or .";
			return false;
		}
		else
		{
		if((str.indexOf("@") == 0) || (str.indexOf(".") == 0))
		{
			fstr="@ or . Cannot Be first";
			return false;
		}
		if((str.indexOf("@") == (str.length-1)) || (str.indexOf(".") == (str.length-1)))
		{
			fstr="@ or . Cannot Be Last";
			return false;
		}

		if(str.indexOf("@") > str.indexOf("."))
		{
			fstr="@ Should be After .";
			return false;
		}
		if((str.indexOf("@")+1) == str.indexOf("."))
		{
			fstr="@. IS Invalid Email";
			return false;
		}
		}
		var cp=0;					
	
		if(cp==2)
		{
			fstr="@ cannnot be repeated";
			return false;
		}
		return true;
		
		
		
		
		
		
		
	}*/
function checkforspecialchars(text)
{
	var iChars = "`~!@#$%^&*()+=-[]\\\';,./{}|\":<>? ";
	for (var i = 0; i < text.length; i++) 
		if (iChars.indexOf(text.charAt(i)) != -1) 
			return true;
	return false;
}
//user id validation starts here
function userid_validate(form)
{	
	if(trim_fun(form.txtuserid.value)=="")
	{
		alert (" enter userID ");
		form.txtuserid.focus();
		return false
	} 
	if(checkforspecialchars(trim_fun(form.txtuserid.value)))
	{
		alert ("Your 'USERID' has special characters. \n \t\t These are not allowed.\n Please remove them and try again.");
		form.txtuserid.focus();
		return false;
	}	
}


function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }

//alert(sText.lastIndexOf('.')  + " " +sText.indexOf(".") ) 
//	return false ;  
   return IsNumber;
   
   }
function checkFileType(imagePath)
 {
var pathLength = imagePath.length;
var lastDot = imagePath.lastIndexOf(".");
var fileType = imagePath.substring(lastDot,pathLength);

if((fileType == ".gif") || (fileType == ".jpg") || (fileType == ".png") || (fileType == ".GIF") || (fileType == ".JPG") || (fileType == ".PNG")) {
return true;
} else {
return false;
}
}

///////////////////////////////////////////////////////////////////////


// Written by ramkiran for validating commision 

function validate_editaff(frm)
{
        if(trim(frm.commision.value)=="")
		{
		alert(" Please enter the commission ");
		frm.commision.focus();
		return false;
		}
		if(isNaN(trim(frm.commision.value)))
		{
		alert(" Please enter only numbers in commission field");
		frm.commision.focus();
		return false;
		}
		if(frm.commision.value>100)
		{
		alert(" Commission percentage must be lessthan or equal to 100  ");
		frm.commision.focus();
		return false;
		}

  return true;
}
// Written By ramkiran for validating refer  a friend




///////////////// WRITTEN BY RAMKIRAN FOR VALIDATING AFFLIATE CHANGE LOGO



function validate_changeLogo(frm)
{

	imagepath= trim(frm.logo.value);
	isimage = checkFileType(trim(frm.logo.value));
	if(imagepath=="")
	{
	 alert("Plese select the logo");
	 frm.logo.focus();
	 return false;
	}
    if(isimage==false)
	{
	 alert(" Please select .GIF or .JPG or .JPEG or .PNG Formats Only ");
	 frm.logo.select();
	 return false;
	}
 return true;	
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////




/////////////////////////////////////////////////////////////////////////////////////////////


 // validate registration 

function validate_register(frm)
{

    if(trim(frm.name.value)=="")
	{
	alert("Please enter First name ")
	frm.name.focus()
	return false
	}
	
	if(!isNaN(frm.name.value))
	{
	alert("Only numeric values are not accepted")
	frm.name.focus()
	return false
	}

    if(trim(frm.user_name_last.value)=="")
	{
	alert("Please enter Last Name ")
	frm.user_name_last.focus()
	return false
	}
	
	if(!isNaN(frm.user_name_last.value))
	{
	alert("Only numeric values are not accepted")
	frm.user_name_last.focus()
	return false
	}
	
	 if(trim(frm.email.value)=="")
	{
	alert("Please enter the email address")
	frm.email.focus()
	return false
	}

	if(checkEmail(trim(frm.email.value))==false)
	{
	alert("Please enter a valid email address");
	frm.email.focus();
	return false;
	}
	
	 if(trim(frm.cemail.value)=="")
	{
	alert("Please confirm the email address")
	frm.cemail.focus()
	return false
	}

	if(checkEmail(trim(frm.cemail.value))==false)
	{
	alert("Please enter  valid email address");
	frm.cemail.focus();
	return false;
	}
	if(trim(frm.email.value)!=trim(frm.cemail.value))
	{
	
	alert("Confirm email address must be same as email address");
	frm.email.select();
	return false;
	}

    if(trim(frm.password.value)=="")
	{
	alert("Please enter the password ")
	frm.password.focus()
	return false
	}
	pass= trim(frm.password.value);
	 if(pass.length<6)
	{
	alert("Password must be atleast of 6 characters")
	frm.password.focus()
	return false
	}
	if(trim(frm.cpassword.value)=="")
	{
	alert("Please confirm the password")
	frm.cpassword.focus()
	return false
	}
    if(trim(frm.password.value)!=trim(frm.cpassword.value))
	{
	alert("Confirm password must be same as new password")
	frm.password.focus()
	return false
	}
	if(trim(frm.address.value)=="")
	{
	alert("Please enter the address")
	frm.address.focus()
	return false
	}
	if(trim(frm.city.value)=="")
	{
	alert("Please enter the city")
	frm.city.focus()
	return false
	}
	if(trim(frm.country.value)=="")
	{
	alert("Please select a country")
	frm.country.focus()
	return false
	}
	if(trim(frm.state.value)=="")
	{
	alert("Please select a state")
	frm.state.focus()
	return false
	}
	// checking if state is other
	
	dis = document.getElementById("forstate");
	display =dis.style.display;
	if(display=='')
	{
		if(trim(frm.state2.value)=="")
		{
		alert("Please enter  state in below  text box")
		frm.state2.focus()
		return false
		}
	}
	if(trim(frm.zipcode.value)=="")
	{
	alert("Please enter the zipcode")
	frm.zipcode.focus()
	return false
	}
	/*
	if(isNaN(trim(frm.zipcode.value)))
	{
	alert("Please enter only numeric values in the zipcode")
	frm.zipcode.focus()
	return false
	}
	*/
	if(trim(frm.fax.value)!="")
	{	
		if(isNaN(trim(frm.fax.value)))
		{
		alert("Please enter only numeric values in the fax number field")
		frm.fax.focus()
		return false
		}
	}


	if(trim(frm.phone.value)=="")
	{
	alert("Please enter the phone number ")
	frm.phone.focus()
	return false
	}
	
	if(isNaN(trim(frm.phone.value)))
	{
	alert("Please enter only numeric values in the phone number field")
	frm.phone.focus()
	return false
	}
return true;
}
//////////////////////////////////////////////////////################//////////////////////////////////////////////
// login validate 
function login(frm)
{

   if(trim(frm.email.value)=="")
   {
   alert("Please enter the email address");
   frm.email.focus();
   return false;
   }
	if(checkEmail(trim(frm.email.value))==false)
	{
	alert("Please enter a valid email address");
	frm.email.focus();
	return false;
	}
    if(trim(frm.password.value)=="")
   {
   alert("Please enter the password");
   frm.password.focus();
   return false;
   }
   

return true;
}

//  written by Ram Kiran for validating payonline
//////////////////////////////////////////////////////



////////////////////////////////////////////////////


//////////////////////////////////

/////////////////////  Refer Friend


//  Email Address validation

function checkEmail(str)
{
var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str))
		return true
	else
		return false
}


function isUrl(s) {
	var regexp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
	return regexp.test(s);
}


function validateURL(url)
{
lengthValue = trim(url);
lengthValue = lengthValue.length;
	if(lengthValue != 0)
	{
	var j = new RegExp();
	j.compile("https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?"); 
	lengthValue = trim(url);
		if (!j.test(lengthValue))
		{ 
		alert("Please enter valid URL in new fun.");
		return false;
		}
	}
}

// validate cart 

function validate_cart(frm)
{
  obj= document.getElementsByName("qty[]");
 for(i=0;i<obj.length;i++)
 {
    if(isNaN(obj[i].value))
	 {
	 alert("Please enter only numerics in quantity field")
	 obj[i].focus();
	 return false;
	 }
 }
 return true;
}





function checkDomain(nname)
{
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 = nname;
var val = true;
//alert("url test");
var dot = mai.lastIndexOf(".");
var dname = mai.substring(0,dot);
var ext = mai.substring(dot,mai.length);
//alert(ext);
	
if(dot>2 && dot<57)
{
	for(var i=0; i<arr.length; i++)
	{
	  if(ext == arr[i])
	  {
	 	val = true;
		break;
	  }	
	  else
	  {
	 	val = false;
	  }
	}
	if(val == false)
	{
	  	 alert("Your domain extension "+ext+" is not correct");
		 return false;
	}
	else
	{
		for(var j=0; j<dname.length; j++)
		{
		  var dh = dname.charAt(j);
		  var hh = dh.charCodeAt(0);
		  //alert(dh + " " +hh)
		  if((hh >= 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123) || hh==45 || hh==46)
		  {
			 if((j==0 || j==dname.length-1) && hh == 45)	
		  	 {
		 	  	 alert("Domain name should not begin are end with '-'");
			      return false;
		 	 }
		  }
		else	{
		  	 alert("Your domain name should not have special characters");
			 return false;
		  }
		}
	}
}
else
{
 alert("Invalid url format");
 return false;
}	

return true;
}







function validate_search(frm)
{
	if(trim(frm.query_search.value)=="" || trim(frm.query_search.value)=="Search")
	{
		alert("Please enter search string");
		frm.query_search.focus();
		return false;
	}
	return true;
}




// funtion show hide starts here
function show_hide(val)
{
	//alert(document.getElementById(val).style.display)
	if(document.getElementById(val).style.display)
		document.getElementById(val).style.display = "";
	else
		document.getElementById(val).style.display = "none";
}
// funtion show hide ends here


function insRow(rowIndex,tabid)
{
	 if(rowIndex == null)rowIndex = 0;
	 var x=document.getElementById(tabid).insertRow(rowIndex)
	 var y=x.insertCell(0)
	 var z=x.insertCell(1)
	 y.innerHTML="NEW CELL1"
	 z.innerHTML="NEW CELL2"
}

function appendRow()
{
 var tbody = document.getElementById("t1").getElementsByTagName("tbody")[0];
 var row = document.createElement("TR");
 var cell1 = document.createElement("TD");
 cell1.innerHTML = "NEW ";
 var cell2 = document.createElement("TD");
 cell2.innerHTML = "ROW";
 row.appendChild(cell1);
 row.appendChild(cell2);
 tbody.appendChild(row);
}

function appendCol()
{ 
 var tbody = document.getElementById("t1");
 var i = 0;
 for(i = 0; i < tbody.rows.length; i++){
   var tr = tbody.rows[i];
   var cell = document.createElement("TD");
   cell.innerHTML = "New Cell";
   tr.appendChild(cell);
 }
}

function insCol(colIndex)
{
  var tbody = document.getElementById("t1");
  
  var i = 0;
  for(i = 0; i < tbody.rows.length; i++){
    var tr = tbody.rows[i];
    
    var j = 0;
    var curIdx = 0;
    for(j = 0; j < tr.childNodes.length-1; j++){
       var tdCell = tr.childNodes[j];
       if(tdCell.nodeValue != '\n'){
         if(colIndex == curIdx){
           var cell = document.createElement("TD");
           cell.innerHTML = "New Cell";
           tr.insertBefore(cell,tdCell);
         }         
         curIdx++;         
       }
       
    }
    
  } 
 
}
function roundNumber(num, dec) {
	var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
	return result;
}
 function ajaxFunction(url)
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      		 document.getElementById("datatable").innerHTML =    xmlHttp.responseText;
			//return  xmlHttp.responseText;
      }
    }
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
  }
 function additem()
{
 	if( trim(document.getElementById("item_no").value) == "")
	{
		alert("Please enter Item Number");
		document.getElementById("item_no").focus();
		return false;
	}
	if( trim(document.getElementById("item_name").value) == "")
	{
		alert("Item Name Missing");
		document.getElementById("item_name").focus();
		return false;
	}
	if(trim(document.getElementById("item_no").value) == "")
	{
		alert("Please enter Item Number");
		document.getElementById("item_no").focus();
		return false;
	}
	if( trim(document.getElementById("item_qty").value) == "")
	{
		alert("Please enter Item Quantity");
		document.getElementById("item_qty").focus();
		return false;
	}
	if( isNaN(document.getElementById("item_qty").value)  )
	{
		alert("Please enter Item Quantity correctly ");
		document.getElementById("item_qty").focus();
		return false;
	}
	if(trim(document.getElementById("item_price").value) == "")
	{
		alert("Please enter Item Price");
		document.getElementById("item_price").focus();
		return false;
	}		
	if( isNaN(document.getElementById("item_price").value)   )
	{
		alert("Please enter Item price correctly ");
		document.getElementById("item_price").focus();
		return false;
	}	
		var price = document.getElementById("item_price").value;
		var qty = document.getElementById("item_qty").value;
		total = roundNumber( (price * qty) , 2);
		additemsList();
		clearall();
}
function clearall()
{
	document.getElementById("item_no").value = "";
	document.getElementById("item_name").value = "";
	document.getElementById("item_qty").value = "";
	document.getElementById("item_price").value = "";
 	setfocus();
}
function additemsList()
{
 		 var url="items.php";
		url=url+"?item_no="+document.getElementById("item_no").value
		url=url+"&item_name="+document.getElementById("item_name").value
		url=url+"&item_qty="+document.getElementById("item_qty").value
		url=url+"&item_price="+document.getElementById("item_price").value
		url=url+"&total="+ total;
		url=url+"&sid="+Math.random();
	  rt = ajaxFunction(url);
 }
 function confirmbill()
 {
 	window.location.href = "confirmbill.php";
 }
 function validatebasicreg(frm)
 {
 	 	 	
	 	
	if(trim(frm.business_email.value) == "")
	{	
		alert("Please enter  Business Email ");
		frm.business_email.focus();
		return false;
	}
	if(checkEmail(frm.business_email.value)==false)
	{
		alert("Please enter the valid email address");
		frm.business_email.focus();
		return false;
	}	
	if(trim(frm.password.value) == "")
	{	
		alert("Please enter password ");
		frm.password.focus();
		return false;
	}	 
	if(trim(frm.password.value).length <6)
	{	
		alert("password must have atleast 6 characters ");
		frm.password.focus();
		return false;
	}	 
	if(trim(frm.cpassword.value) == "")
	{	
		alert("Please enter confirm password ");
		frm.cpassword.focus();
		return false;
	}	
	if(trim(frm.cpassword.value) != trim(frm.password.value) )
	{	
		alert("Passwords mismatched .Please re enter ");
		frm.cpassword.focus();
		return false;
	}		
	if(trim(frm.full_name.value) == "")
	{	
		alert("Please enter Full Name ");
		frm.full_name.focus();
		return false;
	}	  	
 	if(trim(frm.designation.value) == "")
	{	
		alert("Please select designation");
		frm.designation.focus();
		return false;
	}	
	if(trim(frm.business_type.value) == "")
	{	
		alert("Please select You are here for? ");
		frm.business_type.focus();
		return false;
	}	
	if(trim(frm.state_code.value) == "")
	{	
		alert("Please enter state code in office phone number ");
		frm.state_code.focus();
		return false;
	}	
	
	if(isNaN(frm.state_code.value)  )
	{	
		alert("Please enter numerics only  in state code of office phone number ");
		frm.state_code.focus();
		return false;
	}	
	if(trim(frm.phone_num.value) == "")
	{	
		alert("Please enter phone number  in office phone number ");
		frm.phone_num.focus();
		return false;
	}	
	
	if(isNaN(frm.phone_num.value)  )
	{	
		alert("Please enter numerics only  in phone number of office phone number ");
		frm.phone_num.focus();
		return false;
	}		
	if(trim(frm.cmp_name.value) == "")
	{	
		alert("Please enter company name");
		frm.cmp_name.focus();
		return false;
	}
	if(trim(frm.cmp_country.value) == "")
	{	
		alert("Please select country name");
		frm.cmp_country.focus();
		return false;
	}
	if(trim(frm.cmp_website.value) == "" ||trim(frm.cmp_website.value) == "http://" )
	{	
		alert("Please enter company website name");
		frm.cmp_website.focus();
		return false;
	}
	if(trim(frm.captcha.value) == "")
	{	
		alert("Please enter Captcha Code");
		frm.captcha.focus();
		return false;
	}
	if(!frm.terms_conds.checked )
	{
		alert("Please Check terms and condition to register ");
		frm.terms_conds.focus();
		return false;
	}
  	
 return true;
 }
 function product_step1(frm)
 {
		if(trim(frm.productname.value) == "")
		{	
			alert("Please enter  product name");
			frm.productname.focus();
			return false;
		}
		if(trim(frm.productdesc.value) == "")
		{	
			alert("Please enter  product Description");
			frm.productdesc.focus();
			return false;
		}	
 }
 function validaterequest()
 {
 	checkobj = document.getElementsByName("request_type[]");
	checked_count = 0;
	for(i=0;i<checkobj.length;i++)
	{
		if(checkobj[i].checked)
		{
			checked_count++;
		}
	}
	if(checked_count < 2)
	{
		alert("Please select atleast two requests");
		return false;
	}
	else
		return true;
 }