// JavaScript Document

function Global_validate(obj)
  {
    var len=obj.length;
	for(i=0;i<len;i++)
	  {
	    if(obj.elements[i].title!='' && obj.elements[i].value=='' && obj.elements[i].disabled==false)
		  {
		    alert(obj.elements[i].title);
			obj.elements[i].focus();
			return false;
		  }
	  }
	return true;
  }
    /*function survey_filter_submit_frm(what)
{
	var survey_filter_val=what.value;
	
	location.href=("./?pulse=5&pi=4&pr_filter_id="+survey_filter_val);
}*/
  function trimspaces(str)
		{
			while((str.indexOf(' ',0) == 0) && (str.length > 1))
			{
				str = str.substring(1, str.length);
			}
			while((str.lastIndexOf(' ') == (str.length - 1) && (str.length > 1)))
			{
				str = str.substring(0,(str.length - 1));
			}
			if((str.indexOf(' ',0) == 0) && (str.length == 1)) str = '';
			return str;
		}
		  
	function validate_form(Obj)
		{
				for ( i = 0; i < Obj.elements.length; i++) {
						formElem = Obj.elements[i];
						//alert(formElem.type);
						//alert(formElem.value);
						
						switch (formElem.type) {
								case 'text':
								case 'password':
								case 'select-one':
								case 'textarea':
								case 'file':
								case 'checkbox':
								case 'select-multiple':
										split_title=formElem.title.split("::");
										if(split_title[0]!='' && trimspaces(formElem.value)=='' && trimspaces(formElem.style.display)!='none' && split_title[0]!='ImageFile'  && split_title[0]!='Description' && split_title[0]!='ValidUrl' && split_title[0]!='ValidUrlRequired' && split_title[0]!='Name' && split_title[0]!='PhoneNo' && split_title[0]!='EmailID' && split_title[0]!='No of Impression' && split_title[0]!='CorrectUrl' && split_title[0]!='Mandatory' && split_title[0]!='Select1' && split_title[0]!='Select2' && split_title[0]!='Quantity1' && split_title[0]!='Quantity2')
										{	
											alert(split_title[1]);
											formElem.focus();
											return false;
										}
										
										if(split_title[0]=='Select1')
										{
											if(document.getElementById('ap_adult_color').value=='' && document.getElementById('ap_youth_color').value=='')
											{	
												alert(split_title[1]);
												formElem.focus();
												return false;
											}
										}
										
										if(split_title[0]=='Select2')
										{
											if(document.getElementById('ap_adult_color').value=='' && document.getElementById('ap_youth_color').value=='')
											{	
												alert(split_title[1]);
												formElem.focus();
												return false;
											}
										}
										
										if(split_title[0]=='Quantity1')
										{
											if(document.getElementById('ap_adult_color').value!='')
											{	
												if(document.getElementById('ap_adult_color_qty').value=='')
												{	
													alert(split_title[1]);
													formElem.focus();
													return false;
												}
											}
										}
										
										if(split_title[0]=='Quantity2')
										{
											if(document.getElementById('ap_youth_color').value!='')
											{	
												if(document.getElementById('ap_youth_color_qty').value=='')
												{	
													alert(split_title[1]);
													formElem.focus();
													return false;
												}
											}
										}
										
										// valid website url in correct format
										if(split_title[0]=='CorrectUrl' && trimspaces(formElem.value)!='' && trimspaces(formElem.style.display)!='none')
										{
											var urlvalidation= /[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/;
											if(!urlvalidation.test(formElem.value.toLowerCase()))
											{
												alert('Url should be in valid format');
												formElem.focus();
												return false;
											}
										}

									
									// field must not left blank, validation for blank field/text box
										if(split_title[0]=='Mandatory' && trimspaces(formElem.value)=='' && trimspaces(formElem.style.display)!='none')
										{
										alert(split_title[1]);
										formElem.focus();
										return false;
										}
										
										//	Not Required : Email validation function
								
									if(split_title[0]=='EmailID'  && trimspaces(formElem.value)!='' && trimspaces(formElem.style.display)!='none')
									{	
										if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,8})+/.test(formElem.value))
										{}
										else{
											alert('Invalid E-mail Address, Please re-enter correct E-mail.');
											formElem.focus();
											return false;
											}
									}
									
									
										// Required : Phone no (+ - . allowed)	validation in this format +91-230.123.123
									var phoneid =/^[\+]?[0-9(\-)?(\.)?]+$/;
										if(split_title[0]=='PhoneNoMandatory' && trimspaces(formElem.value)=='' && trimspaces(formElem.style.display)!='none')
										{
											alert(split_title[1]);
											formElem.focus();
											return false;
										}
										if(split_title[0]=='PhoneNoMandatory' && trimspaces(formElem.value)!='' && trimspaces(formElem.style.display)!='none')
										{
											if(phoneid.exec(formElem.value))
												{
													
												}
											else{
												alert("Please enter valid Phone No!");
												formElem.focus();
												return false;
												}
										}
									
									
									if(split_title[0]=='Promotion From Date')
									{
										if(document.getElementById('promotion_from_date').value!='')
										{
											//Total time for one day
											var one_day=1000*60*60*24; 
											var currentTime = new Date();
											var month = currentTime.getMonth() + 1;
											var day = currentTime.getDate();
											var year = currentTime.getFullYear();
											
											var date1 = day + "-" + month + "-" + year;
											var date2 = document.getElementById('promotion_from_date').value;
											
											var x=date1.split("-");     
											var y=date2.split("-");
											//date format(date,month,Fullyear) 
									
											var date1=new Date(x[0],(x[1]-1),x[2]);
									  
											var date2=new Date(y[0],(y[1]-1),y[2]);
											
											var month1=x[1]-1;
											var month2=y[1]-1;
											
											//Calculate difference between the two dates, and convert to days
				   
											var diff=Math.ceil((date2.getTime()-date1.getTime())/(one_day)); 
											//_Diff gives the diffrence between the two dates.
											
											if(diff<0)
											{
												alert("Please select date greater or equal to current date!");
												formElem.focus();
												return false;
											}
										}
									}
									
									if(split_title[0]=='Promotion To Date')
									{
										if(document.getElementById('promotion_from_date').value!='' && document.getElementById('promotion_to_date').value!='')
										{
											//Total time for one day
											var one_day=1000*60*60*24; 
			
											var date1 = document.getElementById('promotion_from_date').value;
											var date2 = document.getElementById('promotion_to_date').value;
											
											var x=date1.split("-");     
											var y=date2.split("-");
											//date format(date,month,Fullyear) 
									
											var date1=new Date(x[0],(x[1]-1),x[2]);
									  
											var date2=new Date(y[0],(y[1]-1),y[2]);
											
											var month1=x[1]-1;
											var month2=y[1]-1;
											
											//Calculate difference between the two dates, and convert to days
				   
											var diff=Math.ceil((date2.getTime()-date1.getTime())/(one_day)); 
											//_Diff gives the diffrence between the two dates.
											
											if(diff<0)
											{
												alert("Please select date greater or equal to promotion from date!");
												formElem.focus();
												return false;
											}
										}
									}
								
								// Phone no (+ - . allowed)	validation in this format +91-230.123.123
								var phoneid =/^[\+]?[0-9(\-)?(\.)?]+$/;
									if(split_title[0]=='PhoneNo' && trimspaces(formElem.value)!='' && trimspaces(formElem.style.display)!='none')
									{
										if(phoneid.exec(formElem.value))
											{
												
											}
										else{
											alert("Please enter valid Phone No!");
											formElem.focus();
											return false;
											}
											
									}
									
									
										//  Required : Name validation like Vaseem's Ansari 
										if(split_title[0]=='NameRequired' && trimspaces(formElem.value)=='' && trimspaces(formElem.style.display)!='none'){
										alert(split_title[1]);
										formElem.focus();
										return false;
										}
										if(split_title[0]=='NameRequired')
										{
											if (/^[a-zA-Z ']+$/.test(formElem.value))		// spaces can also come 
											{}
											else
											{
												alert('Name should contain only Characters.');
												formElem.focus();
												return false;
											}
										}
										
										//  Name validation like Vaseem's Ansari 
										if(split_title[0]=='Name' && trimspaces(formElem.value)!='' && trimspaces(formElem.style.display)!='none')
										{
											if (/^[a-zA-Z ']+$/.test(formElem.value))		// spaces can also come 
											{}
											else
											{
												alert('Name should contain only Characters.');
												formElem.focus();
												return false;
											}
										}
										
										
										// valid website url in correct format Required field
										if(split_title[0]=='ValidUrlRequired' && trimspaces(formElem.value)=='' && trimspaces(formElem.style.display)!='none')
										{
												alert(split_title[1]);
												formElem.focus();
												return false;
										}
										
										
										if(split_title[0]=='ValidUrlRequired' && trimspaces(formElem.value)!='' && trimspaces(formElem.style.display)!='none' )
										{
			// for url like http://www.facebook.com/
			//var	urlvalidation=/^(http:\/\/)+[a-zA-Z0-9-\.]+\.(com|org|net|mil|edu|ca|co.uk|com.au|gov)\/$/;
			
			// for url like http://www.facebook.com/ansari.vaseem
			//var urlvalidation= /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
			
			// Change by suman
			var urlvalidation= /[A-Za-z0-9\.-]{3,}\.[A-Za-z]{2,8}/;
											if(!urlvalidation.test(formElem.value.toLowerCase()))
											{
												alert('Url should be in valid format');
												formElem.focus();
												return false;
											}
										}
										
										
										
										// valid website url in correct format
										if(split_title[0]=='ValidUrl' && trimspaces(formElem.value)!='' && trimspaces(formElem.style.display)!='none')
										{
										var	urlvalidation=/^(http:\/\/)+[a-zA-Z0-9-\.]+\.(com|org|net|mil|edu|ca|co.uk|com.au|gov)$/;
											if(!urlvalidation.test(formElem.value.toLowerCase()))
											{
												alert('URL should be in valid format \n(http://www.google.com)');
												formElem.focus();
												return false;
											}
										}
										
										
										if(split_title[0]=='Pincode'){
											if (/^[0-9]+$/.test(formElem.value)){
											}else{
												alert('Pincode contain only numeric values.');
												formElem.focus();
												return false;
											}
										}
										if(split_title[0]=='Start Code'){
											if (/^[0-9]+$/.test(formElem.value)){
											}else{
												alert('Start Code contain only numeric values.');
												formElem.focus();
												return false;
											}
										}
										if(split_title[0]=='End Code'){
											if (/^[0-9]+$/.test(formElem.value)){
											}else{
												alert('End Code contain only numeric values.');
												formElem.focus();
												
												return false;
											}
											if(document.getElementById('txtStartCode').value>=document.getElementById('txtEndCode').value ){
												alert("Please enter start value less than end value.");
												return false;
											}
											
										}
										if(split_title[0]=='Fill36' && (trimspaces(formElem.value)=='select' || trimspaces(formElem.value)=='0')){
										if(trimspaces(formElem.value)==0){
											return true;
										}
										alert(split_title[1]);
										formElem.focus();
										return false;
										}
										
										if(split_title[0]=='Phone')
										{
											if(trimspaces(formElem.value)=='')
											{
												alert(split_title[1]);
												formElem.focus();
												return false;
											}
											if (/^[0-9\-]{6,20}$/.test(formElem.value)){
												}else{
												alert('Please enter valid phone number.');
												formElem.focus();
												return false;	
											}
										}
										if(split_title[0]=='Mobile')
										{
											if(trimspaces(formElem.value)=='')
											{
												alert(split_title[1]);
												formElem.focus();
												return false;
											}
											if (/^[0-9\-]{6,20}$/.test(formElem.value)){
												}else{
												alert('Please enter valid mobile.');
												formElem.focus();
												return false;	
											}
										}
										if(split_title[0]=='Code'  && isNaN(formElem.value)){
											alert('Please enter numeric value for code.');
											formElem.focus();
											return false;
										}
										
										if(split_title[0]=='Phone1' ){
											if(trimspaces(formElem.value)=='')
											{
												alert(split_title[1]);
												formElem.focus();
												return false;
											}
											if (/^\d{3}-\d{3}-\d{4}$/.test(formElem.value)){
												}else{
													alert('Please enter valid phone number.');
													formElem.focus();
													return false;
											}
										}
										if(split_title[0]=='Email' ){
											if(trimspaces(formElem.value)=='')
											{
												alert(split_title[1]);
												formElem.focus();
												return false;
											}
											if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,8})+/.test(formElem.value)){
												}else{
													alert('Invalid E-mail Address, Please re-enter.');
													formElem.focus();
													return false;
											}
										}
										if(split_title[0]=='PayPal Id' ){
											if(trimspaces(formElem.value)=='')
											{
												alert(split_title[1]);
												formElem.focus();
												return false;
											}
											if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,8})+/.test(formElem.value)){
												}else{
													alert('Invalid PayPal Id, Please re-enter.');
													formElem.focus();
													return false;
											}
										}
										if(split_title[0]=='Password' && trimspaces(formElem.value)==''){
											alert(split_title[1]);
											formElem.focus();
											return false;
										}
										if(split_title[0]=='Password' ){
											if(formElem.value !='')
											{
												var strLength = formElem.value.length;
												var spaceindex = formElem.value.lastIndexOf(' ');
												if(strLength < 6)
												{
													alert("Please enter password of at least 6 characters.");
													formElem.focus();
													return false;
												}
												if(spaceindex!='-1')
												{
													alert("Please remove space from password");
													formElem.focus();
													return false;
												}
											}
										}
										if(split_title[0]=='OldPassword' && trimspaces(formElem.value)==''){
										alert(split_title[1]);
										formElem.focus();
										return false;
										}
										if(split_title[0]=='OldPassword' ){
											if(formElem.value !='')
											{
												var strLength = formElem.value.length;
												var spaceindex = formElem.value.lastIndexOf(' ');
												if(strLength < 6)
												{
													alert("Please enter old password of at least 6 characters.");
													formElem.focus();
													return false;
												}
												if(spaceindex!='-1')
												{
													alert("Please remove space from old password.");
													formElem.focus();
													return false;
												}
											}
										}
										if(split_title[0]=='NewPassword' && trimspaces(formElem.value)==''){
											alert(split_title[1]);
											formElem.focus();
											return false;
										}
										if(split_title[0]=='NewPassword' ){
											if(formElem.value !='')
											{
												var strLength = formElem.value.length;
												var spaceindex = formElem.value.lastIndexOf(' ');
												if(strLength < 6)
												{
													alert("Please enter new password of at least 6 characters.");
													formElem.focus();
													return false;
												}
												if(spaceindex!='-1')
												{
													alert("Please remove space from new password.");
													formElem.focus();
													return false;
												}
											}
										}
										if(split_title[0]=='ConfirmPassword' ){
											if(trimspaces(formElem.value)!=''){
												if(document.getElementById('txtConfirmPassword').value!=document.getElementById('txtNewPassword').value ){
													alert("New password and confirm password does not match.");
													return false;
												}
											}else {
												alert(split_title[1]);
												formElem.focus();
												return false;
											}
										}
										if(split_title[0]=='Confirm Password' ){
											if(trimspaces(formElem.value)!=''){
												
												if(document.getElementById('txtConfirmPassword').value!=document.getElementById('txtPassword').value ){
													alert("Password and confirm password does not match.");
													return false;
												}
											}else {
												alert(split_title[1]);
												formElem.focus();
												return false;
											}
										}
										if(split_title[0]=='Description' ){
											  tinyMCE.triggerSave(true,true);
  											  var mytextarea = tinyMCE.getContent();
											  if(mytextarea==''){
												alert(split_title[1]);
													return false;	
											  }
											  /*if(mytextarea.length>280)
											  {
												  alert("Your maximum limit of character exceeds from "+split_title[2]);
													return false;	
											  }*/

										}
										
										if(split_title[0]=='Number'){
											if (/^[0-9]+$/.test(formElem.value)){
											}else{
												alert('Please select only numeric values.');
												formElem.focus();
												return false;
											}
										}
										
										if(split_title[0]=='Price'  && isNaN(formElem.value)){
											alert('Please enter numeric value for price.');
											formElem.focus();
											return false;
										}
										if(split_title[0]=='PinCode'  && isNaN(formElem.value)){
											alert('Please enter valid pincode.');
											formElem.focus();
											return false;
										}
										if(split_title[0]=='Starting Price'  && isNaN(formElem.value)){
											alert('Please enter numeric value for starting price.');
											formElem.focus();
											return false;
										}
										if(split_title[0]=='No of Impression'  && trimspaces(formElem.value)!='')
										{
											if(split_title[0]=='No of Impression'  && parseInt(formElem.value)<0)
											{
												alert('Please enter positive value for No of Impression.');
												formElem.focus();
												return false;
											}
											if(isNaN(formElem.value))
											{
												alert('Please enter numeric value for No of Impression.');
												formElem.focus();
												return false;
											}
										}
										if(split_title[0]=='Size' && trimspaces(formElem.value)=='')
										{
											alert(split_title[1]);
											formElem.focus();
											return false;
										}
										if(split_title[0]=='Price'  && parseInt(formElem.value)<0){
											alert('Please enter positive value for price');
											formElem.focus();
											return false;
										}
										if(split_title[0]=='Size'  && parseInt(formElem.value)<0){
											alert('Please enter positive value for size');
											formElem.focus();
											return false;
										}
										if(split_title[0]=='Starting Price'  && parseInt(formElem.value)<0){
											alert('Please enter positive value for starting price');
											formElem.focus();
											return false;
										}
										
										if(split_title[0]=='Agree'){
											if(formElem.type == 'checkbox')
											if(formElem.checked == false)
											{
												alert(split_title[1]);
												formElem.focus();
												return false;
											}
										}
										
										if(split_title[0]=='File' && trimspaces(formElem.value)!='')
										{
											var jpeg_file=formElem.value;
											
											if((jpeg_file.lastIndexOf(".jpg")==-1) && (jpeg_file.lastIndexOf(".jpeg")==-1) && (jpeg_file.lastIndexOf(".JPG")==-1) && (jpeg_file.lastIndexOf(".JPEG")==-1) && (jpeg_file.lastIndexOf(".GIF")==-1) && (jpeg_file.lastIndexOf(".gif")==-1) && (jpeg_file.lastIndexOf(".png")==-1) && (jpeg_file.lastIndexOf(".PNG")==-1) && (jpeg_file.lastIndexOf(".swf")==-1) && (jpeg_file.lastIndexOf(".SWF")==-1)) {
  								 				//alert(jpeg_file.lastIndexOf(".jpg"));
												alert("Please upload only jpg, jpeg, gif, png extention file");
 								  				return false;
											}
											
										}
										
										// validation for image file that is mandatory field, browse button must have valid image files in it.
										if(split_title[0]=='ImageFileMandatory' && trimspaces(formElem.value)=='')
										{
											alert(split_title[1]);
											formElem.focus();
											return false;
										}
										
										if(split_title[0]=='ImageFileMandatory' && trimspaces(formElem.value)!='')
										{
											if(trimspaces(formElem.value)!='')
											{
												if (/(.jpg|.jpeg|.gif|.png|.JPG|.JPEG|.GIF|.PNG|.swf|.SWF)$/.test(formElem.value))
												{}
												else
												{
													alert("Please select image in valid format [.jpg, .jpeg, .gif, .png, .swf]");
													formElem.focus();
													return false;
												}
											}
										}
										
										
										if(split_title[0]=='ImageFile' && trimspaces(formElem.value)!='')
										{
											var jpeg_file=formElem.value;
											
											if((jpeg_file.lastIndexOf(".jpg")==-1) && (jpeg_file.lastIndexOf(".jpeg")==-1) && (jpeg_file.lastIndexOf(".JPG")==-1) && (jpeg_file.lastIndexOf(".JPEG")==-1) && (jpeg_file.lastIndexOf(".GIF")==-1) && (jpeg_file.lastIndexOf(".gif")==-1) && (jpeg_file.lastIndexOf(".png")==-1) && (jpeg_file.lastIndexOf(".PNG")==-1) && (jpeg_file.lastIndexOf(".swf")==-1) && (jpeg_file.lastIndexOf(".SWF")==-1)) {
  								 				//alert(jpeg_file.lastIndexOf(".jpg"));
												alert("Please select image in valid format [.jpg, .jpeg, .gif, .png, .swf]");
 								  				return false;
											}
											
										}
										
									break;
								}
						}//end of for loop
						return true;
		}  

function CheckAll1(obj,name)
{
	var flag=0;
	var count = obj.elements.length;
	for (i=0; i < count; i++) 
	{
		if(obj.elements[i].type == 'checkbox')
			if(obj.elements[i].checked == true)
			flag=flag+1;
	}
	if(flag>0){
		if(confirm("Are you sure to delete selected "+name+"?"))
		{
			document.getElementById('token').value = "deleteall";
			obj.submit();   
		} else {
			var count = obj.elements.length;
			for (i=0; i < count; i++) 
			{
				obj.elements[i].checked =0;
				flag=false;
			}return false;	
		}
	}else {
		alert("Please select at least one "+name+".");
		return false;
	}
}

function AddProductCheck(obj,name)
{
	var flag=0;
	var count = obj.elements.length;
	for (i=0; i < count; i++) 
	{
		if(obj.elements[i].type == 'checkbox')
			if(obj.elements[i].checked == true)
			flag=flag+1;
	}
	if(flag>0){
		if(confirm("Are you sure to add selected "+name+"?"))
		{
			document.getElementById('token').value = "addall";
			obj.submit();   
		} else {
			var count = obj.elements.length;
			for (i=0; i < count; i++) 
			{
				obj.elements[i].checked =0;
				flag=false;
			}return false;	
		}
	}else {
		alert("Please select at least one "+name+".");
		return false;
	}
}

function CheckAll(obj)
{
	var count = obj.elements.length;

	for (i=0; i < count; i++) 
	{
		//if(obj.elements[i].type == 'checkbox' && obj.elements[i].id == 'chk')
		if(obj.elements[i].type == 'checkbox')
			obj.elements[i].checked = obj.chkall.checked;
	}
}

function textCounter(field,cntfield,maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else
cntfield.value = maxlimit - field.value.length;
}

// usage - adding new input box when user clicks on add more, used in add products manager
function addElement() {
	  	var ni = document.getElementById('myDiv');
	  	var numi = document.getElementById('theValue');
		if(document.getElementById('theValue').value=='')
			document.getElementById('theValue').value=1;
		
	  	var num = (document.getElementById('theValue').value -1)+1;
	  	numi.value = num+1;
	  	var newdiv = document.createElement('div');
		//alert(num);
		var divIdName = num+1;
		//if(num!=1){
//			alert('hi');
//	  		var divIdName = num;
//		}
//		else{	alert('bye');
//			var divIdName = num+1;
//		}
	  	newdiv.setAttribute('id',divIdName);
	  	newdiv.innerHTML = '<table width=\'449\' id=\''+divIdName+'\'><tr><td nowrap=\'nowrap\' class=\'text-cont\' width=\'141\' height=\'30\'>Size '+divIdName+'/Volumes '+divIdName+'<\/td><td width=\'85\'><input class=\'text-box\' style=\'width:60px;\' name=\'txtSize'+divIdName+'\' value=\'\' type=\'text\' size=\'5\' title=\'Size'+divIdName+'/Volumes'+divIdName+'::Please enter size'+divIdName+'/volume'+divIdName+'.\' \/><\/td><td nowrap=\'nowrap\' width=\'50\' class=\'text-cont\' height=\'30\'>Price '+divIdName+'<\/td\><td width=\'62\'><input  class=\'text-box\' onKeyUp=\'validation4number(this,"notnumbers")\' style=\'width:60px;\' name=\'txtPrice'+divIdName+'\' value=\'\' type=\'text\' size=\'5\' title=\'Price'+divIdName+'::Please enter price'+divIdName+'.\' \/><\/td><td width=\'87\' height=\'30\' nowrap=\'nowrap\' class=\'text-cont\'><a href=\'javascript:;\'   style=\'font:normal 12px Arial, Helvetica, sans-serif ; outline:none; color:#000000;\' onclick=\'removeElement('+divIdName+')\'>Remove</a><\/td><\/tr><\/table>';
		ni.appendChild(newdiv);
	}


function addNewRow() {
	  	var ni = document.getElementById('myDiv');
	  	var numi = document.getElementById('total');
		if(document.getElementById('total').value ==10)
		  {
			alert("you can not add more email.");
			return false;
		  }
		if(document.getElementById('total').value=='')
			document.getElementById('total').value=1;
		
	  	var num = (document.getElementById('total').value -1)+1;
	  	numi.value = num+1;
	  	var newdiv = document.createElement('div');
		
		var divIdName = num+1;
		
	  	newdiv.setAttribute('id',divIdName);
	  	newdiv.innerHTML = '<table id=\''+divIdName+'\'><tr><td height=\'18\' class=\'refer-left01\'><span>*</span>Friend\'s First Name<br><input name=\'name_'+divIdName+'\' type=\'text\' class=\'refer-box\' id=\'name_'+divIdName+'\' title=\'Friend Name::Please enter friend\'s name!\'/><\/td><td height=\'18\' class=\'refer-left01\'><span>*</span>Email Address '+divIdName+'<br><input name=\'sendEmail_'+divIdName+'\' type=\'text\' class=\'refer-box\' id=\'sendEmail_'+divIdName+'\' title=\'Please enter email!\'/><\/td><td><a href=\'javascript:;\' onclick=\'removeNewElement('+divIdName+')\'>Remove</a><\/td><\/tr><\/table>';
		ni.appendChild(newdiv);
	}
	
	function removeNewElement(divNum) {
	  var d = document.getElementById('myDiv');
	  var olddiv = document.getElementById(divNum);
	  d.removeChild(olddiv);
	  document.getElementById('total').value = document.getElementById('total').value -1;
	}

	function removeElement(divNum) {
	  var d = document.getElementById('myDiv');
	  var olddiv = document.getElementById(divNum);
	  d.removeChild(olddiv);
	  document.getElementById('theValue').value = document.getElementById('theValue').value -1;
	}

// this function is used to show and hide div on click of radio button
function toggle(thediv) 
{	
	//alert(thediv);
	if(document.getElementById(thediv).style.display == 'none')
	{
		document.getElementById(thediv).style.display='block';
	}
	else
	{
		document.getElementById(thediv).style.display = 'none';
	}
}
// usage onKeyUp="validation4number(this,'notnumbers')"
//var r2={ 'notnumbers':/[^\d\-]/g}
var r2={ 'notnumbers':/[^\d]/g}
function validation4number(o,w)
{
  o.value = o.value.replace(r2[w],'');
}

// Value greater that 0 (not .decimal allowed)
var r3={ 'notnumbers':/[^\d]/g}
function validation4numeric(o,w)
{
  o.value = o.value.replace(r2[w],'');
}

function amountFormat(objID)
{
	//if(document.getElementById(objID).value=='')
//		document.getElementById(objID).value=0.00;
	var myString = new String();
	myString = document.getElementById(objID).value;
	document.getElementById(objID).value=myString.replace(/[a-zA-Z]|\+|\-|`|~|!|@|#|\$|%|\^|\&|\*|\(|\)|\_|\=|,|<|>|\/|\?|\||\\|\;|\:|\'|\"/,"");
	var counrDot=myString.split(".");
	if(counrDot.length > 2)
	{
		document.getElementById(objID).value=myString.replace(/\.$/,"");
	}
	if(document.getElementById(objID).value > 99999999)
		document.getElementById(objID).value=1;
}

function opendIV(value)
{
	if(document.getElementById(value))
		document.getElementById(value).style.display='block';
}

function closedIV()
{
	for(var i=1;i<=20;i++)
	{
		if(document.getElementById(i))
				document.getElementById(i).style.display='none';
	}
}

function days_between(date1, date2) {
    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24;

    // Convert both dates to milliseconds
    var date1_ms = date1.getTime();
    var date2_ms = date2.getTime();

    // Calculate the difference in milliseconds
    var difference_ms = Math.abs(date1_ms - date2_ms);
    
    // Convert back to days and return
    return Math.round(difference_ms/ONE_DAY);
}

function widthHeight()
{
	var btypeId=document.getElementById('btype_id').value;
	var width;
	var height;
	
	if(btypeId==1)
	{
		width	=	710;
		height	=	347;
	}
	else if(btypeId==2)
	{
		width	=	710;
		height	=	67;
	}
	else if(btypeId==3)
	{
		width	=	160;
		height	=	600;
	}
	else if(btypeId==4)
	{
		width	=	200;
		height	=	200;
	}
	
	var imgWidth	=	document.getElementById('bannerFile').clientWidth;
	var imgHeight	=	document.getElementById('bannerFile').clientHeight;
	
	if(imgWidth<width || imgHeight<height)
	{
		alert('Please select image according to the banner type width and height\nYour image width and height is '+imgWidth+' x '+imgHeight);
		return false;
	}
	else
		return true;
}
