// 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 'radio':
								case 'select-multiple':
										split_title=formElem.title.split("::");
										if(split_title[0]!='' && trimspaces(formElem.value)=='' && 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]!='Phone' && split_title[0]!='Mobile' && split_title[0]!='MobileNo' && split_title[0]!='EmailID' && split_title[0]!='No of Impression' && split_title[0]!='CorrectUrl' && split_title[0]!='Mandatory')
										{
										if(formElem.style.display!='none')
										{
											alert(split_title[1]);
											formElem.focus();
											return false;
										}
										}
										// valid website url in correct format
										if(split_title[0]=='CorrectUrl')
										{
											if(trimspaces(formElem.value)!='')
											{
												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;
												}
											}
											else
											{
												alert(split_title[1]);
												formElem.focus();
												return false;
											}
										}

									
									// field must not left blank, validation for blank field/text box
										if(split_title[0]=='Mandatory' && trimspaces(formElem.value)=='')
										{
										alert(split_title[1]);
										formElem.focus();
										return false;
										}
										
										//	Not Required : Email validation function
								
									if(split_title[0]=='EmailID'  && trimspaces(formElem.value)!='')
									{	
										if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.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)=='')
										{
											alert(split_title[1]);
											formElem.focus();
											return false;
										}
										if(split_title[0]=='PhoneNoMandatory' && trimspaces(formElem.value)!='')
										{
											if(phoneid.exec(formElem.value))
												{
													
												}
											else{
												alert("Please enter valid Phone No!");
												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)!='')
									{
										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)==''){
										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)!='')
										{
											if (/^[a-zA-Z ']+$/.test(formElem.value))		// spaces can also come 
											{}
											else
											{
												alert('Name should contain only Characters.');
												formElem.focus();
												return false;
											}
										}
										
										if(split_title[0]=='NameSpl' && trimspaces(formElem.value)=='') {
										alert(split_title[1]);
										  formElem.focus();
										    return false;
										}
									if(split_title[0]=='NameSpl' )
										{
											if(formElem.value !='')
											{
													var strLength = formElem.value.length;
													//var iChars = "!@$%^&*()+=-[]\\\';,/{}|\":<>?~_"; 
													var iChars = "!@$%^&*()+=[]\\\;/{}|\":<>?~_"; 
													for (var j = 0; j < strLength; j++) 
													{
														if (iChars.indexOf(formElem.value.charAt(j)) != -1) 
														{
															alert ("Special characters not allowed in name.");
															formElem.focus();
															return false;
														}
													}	
											}
											if(!check_name(formElem.value))
											{
												alert("Invalid entry! Please re-enter first name.");
												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 non mandatory
										if(split_title[0]=='ValidUrlNM' && trimspaces(formElem.value)!='')
										{
									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;
											}
										}
										
										// valid website url in correct format
										if(split_title[0]=='ValidUrl' && trimspaces(formElem.value)!='')
										{
										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 \n(http://www.google.com)');
												formElem.focus();
												return false;
											}
										}
										
										
										if(split_title[0]=='Pincode' && formElem.style.display!='none'){
											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(document.getElementById('cmobile'))
											{
												if(trimspaces(formElem.value)=='' && document.getElementById('cmobile').value=='')
												{
													alert(split_title[1]);
													formElem.focus();
													return false;
												}
											}
											else
											{
												if(trimspaces(formElem.value)=='')
												{
													alert(split_title[1]);
													formElem.focus();
													return false;
												}
											}
											if(trimspaces(formElem.value)!='')
											{
												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)=='' && document.getElementById('cphone').value=='')
											{
												alert(split_title[1]);
												formElem.focus();
												return false;
											}
											if(trimspaces(formElem.value)!='')
											{
												if (/^[0-9\-]{6,20}$/.test(formElem.value) && document.getElementById('cmobile').value.length>=10){
													}else{
													alert('Please enter valid mobile number.');
													formElem.focus();
													return false;	
												}
											}
										}
										
										if(split_title[0]=='MobileNoMandatory')
										{
											if(trimspaces(formElem.value)=='')
											{
												alert(split_title[1]);
												formElem.focus();
												return false;
											}
											if(trimspaces(formElem.value)!='')
											{
												if (/^[0-9\-]{6,20}$/.test(formElem.value)){
													}else{
													alert('Please enter valid mobile number.');
													formElem.focus();
													return false;	
												}
											}
										}
										if(split_title[0]=='MobileNo')
										{
											if(trimspaces(formElem.value)!='')
											{
												if (/^[0-9\-]{6,20}$/.test(formElem.value)){
													}else{
													alert('Please enter valid mobile number.');
													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,3})+$/.test(formElem.value)){
												}else{
													alert('Please enter valid email id.');
													formElem.focus();
													return false;
											}
										}
										
										if(split_title[0]=='Confirm_Email' ){
											if(trimspaces(formElem.value)!=''){
												if(document.getElementById('email').value!=document.getElementById('confirm_email').value ){
													alert("Email and Confirm Email value does not match.");
													formElem.focus();
													return false;
												}
											}else
											{
												alert(split_title[1]);
												formElem.focus();
												return false;
											}
											if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.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,3})+$/.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("Password and Confirm password does not match.");
													formElem.focus();
													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;
											}
											
										}
										
										//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////									
	//sushil code								
									var rdok='n';
									
										if(split_title[0]=='rdchk' && formElem.type=='radio')
										{
					
											var rdlen = Obj.elements[formElem.name].length; 
											for (var j=0; j <rdlen; j++) 
											{
												if(Obj.elements[formElem.name][j].checked) 
												{
													rdok='y';
													break;
													//return true;
												}
											}
											if(rdok=='n')
											{
												alert(split_title[1]);
												formElem.focus();
												return false;	
											}
										}
									
									var chkok='n';
										if(split_title[0]=='checkbxchk' && formElem.type=='checkbox')
										{
											
											var totchk=Obj.elements[formElem.name].length;
											for (m=0; m < totchk; m++) 
											{
												if(Obj.elements[formElem.name][m].type == 'checkbox')
												{
													if(Obj.elements[formElem.name][m].checked) 
													{
														chkok='y';
														break;
														//return true;
													}	
												}
											}
											if(chkok=='n')
											{
												alert(split_title[1]);
												formElem.focus();
												return false;	
											}
										}
										
										
											//validation for the name for accept only character
										
										
										if(split_title[0]=='NameSus' && trimspaces(formElem.value)=='') {
										alert(split_title[1]);
										  formElem.focus();
										    return false;
										}
										function check_name(value) {
  return value.match( /^[A-Za-z][A-Za-z0-9 ]*/ );
}
									if(split_title[0]=='NameSus' )
										{
											if(formElem.value !='')
											{
													var strLength = formElem.value.length;
													//var iChars = "!@$%^&*()+=-[]\\\';,/{}|\":<>?~_"; 
													var iChars = "!@$%^&*()+=[]\\\;/{}|\":<>?~_."; 
													for (var j = 0; j < strLength; j++) 
													{
														if (iChars.indexOf(formElem.value.charAt(j)) != -1) 
														{
															alert ("Special characters are not allowed.");
															formElem.focus();
															return false;
														}
													}	
											}
											if(!check_name(formElem.value))
											{
												alert("Invalid entry! Please re-enter name.");
												formElem.focus();
												return false;
											}
										}
										
										// end validation for name
										
										
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
										
										// 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)$/.test(formElem.value))
												{}
												else
												{
													alert("Please select image in valid format [.jpg, .jpeg, .gif, .png]");
													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)) {
  								 				//alert(jpeg_file.lastIndexOf(".jpg"));
												alert("Please select image in valid format [.jpg, .jpeg, .gif, .png]");
 								  				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 id=\''+divIdName+'\'><tr><td align=\'right\' nowrap=\'nowrap\'>Size '+divIdName+'/Volumes '+divIdName+'<span class="red2">&nbsp;</span><\/td><td><input name=\'txtSize'+divIdName+'\' value=\'\' type=\'text\' size=\'5\' title=\'Size'+divIdName+'/Volumes'+divIdName+'::Please enter size'+divIdName+'/volume'+divIdName+'.\' \/><\/td><td nowrap=\'nowrap\' align=\'right\'>Price '+divIdName+'<span class="red2">&nbsp;</span><\/td\><td><input name=\'txtPrice'+divIdName+'\' value=\'\' type=\'text\' size=\'5\' title=\'Price'+divIdName+'::Please enter price'+divIdName+'.\' \/><\/td><td><a href=\'javascript:;\' 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 width=\'540\' id=\''+divIdName+'\'><tr><td height=\'18\' align=\'left\' class=\'email\'><span>*</span>Friend\'s First Name<br><input name=\'name_'+divIdName+'\' type=\'text\' class=\'email-box\' id=\'name_'+divIdName+'\' title=\'Friend Name::Please enter friend\'s name!\'/><\/td><td height=\'18\' align=\'left\' class=\'email\'><span>*</span>Email Address '+divIdName+'<br><input name=\'sendEmail_'+divIdName+'\' type=\'text\' class=\'email-box\' id=\'sendEmail_'+divIdName+'\' title=\'Please enter email!\'/><\/td><td align=\'left\'><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;
	}

/******************************/
function addNewRowj() {
	  	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 removeNewElementj(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}
function validation4number(o,w)
{
  o.value = o.value.replace(r2[w],'');
}
function validation4pnumber(o,w)
{
  o.value = o.value.replace(r2[w],'');
  if(o.value <=0)
  {
	alert('Please enter valid quantity.');
	o.value=0;
  }
}
// Value greater that 0 (not .decimal allowed)
var r3={ 'notnumbers':/[^\d]/g}
function validation4numeric(o,w)
{
  o.value = o.value.replace(r2[w],'');
 // o.value = o.value.replace(0,'');
  
}

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;
		
	}
	//alert(document.getElementById(objID).value);
	if(document.getElementById(objID).value<1)
	{
		alert('Please enter valid Amount.');
	 }
}

function showTerms(file)
{
	window.open(file,"mywindow","location=1,status=1,scrollbars=1,width=538,height=630");
	return false;
}

function opendIV(value)
{
	if(document.getElementById(value))
		document.getElementById(value).style.display='block';
	if(document.getElementById('txtEmail').value!='')
		closedIV();	
}

function closedIV()
{
	for(var i=1;i<=20;i++)
	{
		if(document.getElementById(i))
				document.getElementById(i).style.display='none';
	}
}
