String.prototype.trim = function()  {
    // skip leading and trailing whitespace and return everything in between
    return this.replace(/^\s*(\b.*\b|)\s*$/, "$1");
}

function _add() {
   	var f = $('frmMain');
    var pga = f['hdnPgaction'];
    $(pga).value = 'add';
	f.submit();
}
function _addforum() {
   	var f = $('frmMain');
    var pga = f['hdnPgaction'];
    $(pga).value = 'addforum';
	f.submit();
}
function _onlyedituser(fld,id) {
	alert("abcd")
   	var f = $('frmMain');
    var pga = f['hdnPgaction'];
    $(pga).value = 'edit';
    var fid = f[fld];
    $(fid).value = id;
	//alert(pageNo);
	//var pno = f['hdnPageNo'];
	//$(pno).value = pageNo;
	//alert($(pno).value);
	f.submit();
}

function _edit(fld,id,pageNo) {	
   	var f = $('frmMain');
    var pga = f['hdnPgaction'];
    $(pga).value = 'edit';
    var fid = f[fld];
    $(fid).value = id;
	//alert(pageNo);
	var pno = f['hdnPageNo'];
	$(pno).value = pageNo;
	//alert($(pno).value);
	f.submit();
}

function _delete(fld,id) {
	if(confirm('Are you sure to remove this record?')) {
        var f = $('frmMain');
        var pga = f['hdnPgaction'];
        $(pga).value = 'delete';
        var fid = f[fld];
		$(fid).value = id;
		f.submit();
    }
}


function Change_Status(fld,id,status_action) {
	var st = confirm('Want to change status !!');
	if(st) {
		var f = $('frmMain');
		var pga = f['hdnPgaction'];
		$(pga).value = 'change_status';
		var fid = f['fld'];
		$(fid).value = fld;
		var hid = f['hdn_fld_id'];
		$(hid).value = id;
		var s_action  = f['status_action'];
		$(s_action).value = status_action;
		f.submit();
		return true;
	}
}


function Change_Subscriber_Status(fld,id,status_action) {
	var st = confirm('Want to change Newsletter !!');
	if(st) {
		var f = $('frmMain');
		var pga = f['hdnPgaction'];
		$(pga).value = 'Change_Subscriber_Status';
		var fid = f['fld'];
		$(fid).value = fld;
		var hid = f['hdn_fld_id'];
		$(hid).value = id;
		var s_action  = f['status_action'];
		$(s_action).value = status_action;
		f.submit();
		return true;
	}
}

function Bulk_Delete(frmMain,chk_deleted_ids) {
	var str = "";
	var flag = 0;
	var len = document.frmMain.chk_deleted_ids.length;
	if(len>0) {
		for(i=0;i<len;i++) {
			if(document.frmMain.chk_deleted_ids[i].checked==true) {
				str+=document.frmMain.chk_deleted_ids[i].value+",";
				flag = 1;
			}
		}
	}
	else {
		if(document.frmMain.chk_deleted_ids.checked==true) {
				str+=document.frmMain.chk_deleted_ids.value+",";
				flag = 1;
		}
	}
	if(flag == 0) {
		alert("please select atleast one record");
		return false;
	}
	else {
		var f = $('frmMain');
		var pga = f['hdnPgaction'];
		$(pga).value = 'delete_selected';
		var del_sel_records = f['del_selected_records'];
		$(del_sel_records).value = str;
		return true;
	}
}
// end of Bulk_Delete


function arrange_order(orderbyfld,orderby) {
	var f = $('frmMain');
	var obyfld = f['hdnOrderbyFieldname'];
	$(obyfld).value = orderbyfld;
	var oby = f['hdnOrderby'];
	$(oby).value = orderby;
	f.submit();
}

// end of arrange_order
var isChecked = false;
function checkAll(frmMain) {
	var check;
	check=false;
	if (isChecked) {
		isChecked = false;
		check = false;
	} else {
		isChecked = true;
		check = true;
	}		
	for(var i=0;i<=frmMain.elements.length-1;i++) {
		if (check) { 
			document.frmMain.elements[i].checked=true;
		} else {
			document.frmMain.elements[i].checked=false;
		}
	}
} 
// end of checkAll



function _forgetpassword() {
   	var f = $('frmMainval');
    var pga = f['hdnPgactionval'];
    $(pga).value = 'forgetpassword';
	f.submit();
}




function Page_submit(){
	var f = $('frmMain');
	var pga = f['hdnPgaction'];
	$(pga).value = 'page_submit';
    return true;
}

// Check function start 

function _CheckNumeric(e) {   
    var key = (window.event) ? event.keyCode : e.which;   
	if (window.event)     
	    key = event.keyCode   
	else     key = e.which   // Was key that was pressed a numeric character (0-9) or backspace (8)?   
	if ( key > 47 && key < 58 || key == 8 )    
	 return; // if so, do nothing   
	else // otherwise, discard character     
	if (window.event) //IE      
	// window.event.returnValue = null;    
	window.event.keyCode=0;
	  else //Firefox       
	  e.preventDefault(); 
}

function _CheckNumericPrice(e) {   
    var key = (window.event) ? event.keyCode : e.which;   
	//alert(key);
	if (window.event)     
	    key = event.keyCode   
	else     key = e.which   // Was key that was pressed a numeric character (0-9) or backspace (8)?   46==>.
	if ( key > 47 && key < 58 || key == 8 || key == 46)    
	 return; // if so, do nothing   
	else // otherwise, discard character     
	if (window.event) //IE      
	// window.event.returnValue = null;    
	window.event.keyCode=0;
	  else //Firefox       
	  e.preventDefault(); 
}

// Check function end 

function mass_mail() {
	var f = $('frmMain');
    var pga = f['hdnPgaction'];
    $(pga).value = 'mass_mail';
	f.submit();
}

function Select_all() {
	var len = document.frmMain.subscriber.length;
	if(len>0) {
		for(i=0;i<len;i++) {
			document.frmMain.subscriber[i].selected=true;
		}
	}
}

function Deselect_all() {
	var len = document.frmMain.subscriber.length;
	if(len>0) {
		for(i=0;i<len;i++) {
			document.frmMain.subscriber[i].selected=false; 
		}
	}
}

// _cancel function start 
function _cancel(page_name,hdnPageNo) {
	//alert(hdnPageNo);
	if(hdnPageNo == '') {
		hdnPageNo = 1;
	}
	var redirect = page_name + "?hdnPageNo=" + hdnPageNo;
	location.href = redirect;
}
// _cancel function end


function get_sub_category(cat_id,sel_cat_id) {
		//alert(cat_id);
		new Ajax.Request('ajax_get_sub_category.php',
		{
			method: 'get',
			parameters: {cat_id: cat_id, sel_cat_id:sel_cat_id},			
			onSuccess: handleHttpResponse		
		});
	}

	function handleHttpResponse(transport) {
		var results=transport.responseText;
		objDiv = document.getElementById('sub_cat');
		if(transport.responseText != ""){
			res_divText=results.split("~");
			objDiv.innerHTML=res_divText[0];
		}
  }
  
  
  
  
function check_frm()
{
	var first_name = document.getElementById('first_name').value;
	var last_name = document.getElementById('last_name').value;
	var business_phone = document.getElementById('business_phone').value;
	var email = document.getElementById('email').value;
	var city = document.getElementById('city').value;
	var zip_postal_code = document.getElementById('zip_postal_code').value;
	var state_province = document.getElementById('state_province').value;
	var product_description = document.getElementById('product_description').value;
	
	    if(first_name == "")
		 {
		  alert('First Name required.Please enter it.');
		  document.getElementById('first_name').focus();
		  return false;
		 }
		 
	    if(last_name == "")
		 {
		  alert('Last Name required.Please enter it.');
		  document.getElementById('last_name').focus();
		  return false;
		 }
		 
		if(business_phone == "")
		   {
			alert('Business Phone required. Please enter it.');
			return false;
		   }
		   
	    if(email == "")
		  {
		    alert('Email required.Please enter it.');
			return false;
		  }
				
		if(city == "")
		  {
		    alert('City required.Please enter it.');
			return false;
		  }
		  
		if(zip_postal_code == "")
		  {
		    alert('Zip or Postal Code required.Please enter it.');
			return false;
		  }
		  
		if(state_province == "")
		  {
		    alert('State or Province Name required.Please enter it.');
			return false;
		  }
		  
		if(product_description == "")
		  {
		    alert('Product description required.Please enter it.');
			return false;
		  }
				
		 else
				{
					document.getElementById('frmMain').submit();
				}
}
	
function get_all_states(val){
	//alert(val);
	if(document.forms[0].country_id.value == "99")
	{
		var india = document.getElementById('India');
		india.style.display="inline";
		var others = document.getElementById('Other');
		others.style.display="none"; 
		
	}
	else
	  {
		var others = document.getElementById('Other');
		others.style.display="inline";  
		var india = document.getElementById('India');
		india.style.display="none";
		  
	  }
}



function Content_Validity_Check(action) {
	var f = $('frmMain');
	var pga = f['hdnPgaction'];
	var c_name = f['content_name'];
	if ($F(c_name).search(/\S/) == -1) {
		alert('Please enter Content Title');
		$(c_name).focus();
		return false;
	}
	var oEditor = FCKeditorAPI.GetInstance('content_content') ; // Get the editor instance that we want to interact with

	var test_content = oEditor.GetXHTML( true ) ;
	if(test_content=="")
	{
		alert("Content Cannot be blank");
		return false;
	}
	$(pga).value = action;
	return true;
} 



function Video_Check(action) {
	//alert(action);
	var f = $('frmMain');
	var pga = f['hdnPgaction'];

	var video_title = f['video_title'];
	if ($F(video_title).search(/\S/) == -1) {
		alert('Please enter title');
		$(video_title).focus();
		return false;
	}
	if(action == 'insert'){
		var video_path = f['video_path'];
		if ($F(video_path).search(/\S/) == -1) {
			alert('Please upload video');
			$(video_path).focus();
			return false;
		}
	}
	var video = document.frmMain.video_path.value;
	if(video != "") {
		var video_arr = video.split(".");
		var video_path = video_arr[1].toUpperCase();
		if(video_path!="FLV" && video_path!="MP4"){
			alert("Please upload a .FLV/.MP4 file only");
			document.frmMain.video_path.focus();
			return false;
		}
	}
	var image = document.frmMain.video_image.value;
	if(image != "") {
		var image_arr = image.split(".");
		var video_image = image_arr[1].toUpperCase();
		if(video_image!="GIF" && video_image!="JPG" && video_image!="JPEG" && video_image!="PNG" && video_image!="BMP"){
			alert("Please upload .GIF/.JPG/.JPEG/.PNG/.BMP file only");
			document.frmMain.video_image.focus();
			return false;
		}
	}
	$(pga).value = action;
	return true;
}



function News_Validity_Check(action) {
	var f = $('frmMain');
	var pga = f['hdnPgaction'];
	var news_title = f['news_title'];
	var news_image = f['news_image'];
	//var news_title_sp = f['news_title_sp'];
	if ($F(news_title).search(/\S/) == -1) {
		alert('Please enter news title');
		$(news_title).focus();
		return false;
	}
	
	if(action == 'insert'){
	if ($F(news_image).search(/\S/) == -1) {
		alert('News image can not be left blank');
		$(news_image).focus();
		return false;
	}}
	
	if (document.frmMain.news_image.value != '') {
		var d_image = document.frmMain.news_image.value;
		var image_arr = d_image.split(".");
		var dept_image = image_arr[1].toUpperCase();
		if(dept_image!="GIF" && dept_image!="JPG" && dept_image!="JPEG" && dept_image!="BMP"){
			alert("Please upload a .GIF/.JPG/.JPEG/.BMP file in news image");
			document.frmMain.news_image.focus();
			return false;
		}
	}
	
	var oEditor_news_body = FCKeditorAPI.GetInstance('news_body') ;
    var news_body = oEditor_news_body.GetXHTML( true ) ;
	if(news_body=="") {
        alert('Please enter news');
		return false;
	}
	
	$(pga).value = action;
	return true;
	
}
// end of News_Validity_Check


function emailCheck(entry) {
    if ( (/^[a-zA-Z0-9-._]+(@[a-zA-Z0-9-.]{1,}[a-zA-Z0-9_.-]+\.)+[a-zA-Z]{2,4}$/).exec(entry) == null) {
        return false;
    }
    return true;
}

function PhoneValidate(entry)
{
   if(entry.search(/\d{3}\-\d{3}\-\d{4}/)==-1)
   {
      return false;
   }
   return true;
}

function FaxValidate(entry)
{
   if(entry.search(/\d{3}\-\d{3}\-\d{4}/)==-1)
   {
      return false;
   }
   return true;
}

function zipValidate(entry)
{
   if(entry.search(/\d{6}/)==-1)
   {
      return false;
   }
   return true;
}

function isZip(s) 
{

     // Check for correct zip code
     reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);

     if (!reZip.test(s)) {
          //alert("Zip Code Is Not Valid");
          return false;
     }

return true;
}
// start of contact_info_validity_check

function ContactUs_Validity_Check(action) {
	//alert(action);
	var f = $('frmMain');
	var pga = f['hdnPgaction'];
	
	var first_name = f['first_name'];
	var last_name = f['last_name'];
	var company_name = f['company_name'];
	var business_phone = f['business_phone'];
	var fax = f['fax'];
	var email = f['email'];
	var street1 = f['street1'];
	var street2 = f['street2'];
	var city = f['city'];
	var zip_postal_code = f['zip_postal_code'];
	var state_province = f['state_province'];
	var product_description = f['product_description'];
	var method_of_contact = f['method_of_contact'];
	
	if ($F(first_name).search(/\S/) == -1) {
		alert('Please enter first name');
		$(first_name).focus();
		return false;
	}
	if ($F(last_name).search(/\S/) == -1) {
		alert('Please enter last name');
		$(last_name).focus();
		return false;
	}
	if ($F(company_name).search(/\S/) == -1) {
		alert('Please enter company name');
		$(company_name).focus();
		return false;
	}
	if ($F(business_phone).search(/\S/) == -1) {
		alert('Please enter business phone');
		$(business_phone).focus();
		return false;
	}
	if(PhoneValidate($F(business_phone))==false) {
		alert('The phone number you entered is not valid.\r\nPlease enter a phone number with the format xxx-xxx-xxxx.');
		$(business_phone).focus();
		return false;
	}
	if ($F(fax).search(/\S/) == -1) {
		alert('Please enter fax');
		$(fax).focus();
		return false;
	}
	if(FaxValidate($F(fax))==false) {
		alert('The fax number you entered is not valid.\r\nPlease enter a fax number with the format xxx-xxx-xxxx.');
		$(fax).focus();
		return false;
	}
	if ($F(email).search(/\S/) == -1) {
		alert('Please enter email');
		$(email).focus();
		return false;
	}
	if(emailCheck($F(email))==false) {
		alert('Please enter valid email');
		$(email).focus();
		return false;
	}
	if ($F(street1).search(/\S/) == -1) {
		alert('Please enter street1');
		$(street1).focus();
		return false;
	}
	if ($F(street2).search(/\S/) == -1) {
		alert('Please enter street2');
		$(street2).focus();
		return false;
	}
	if ($F(city).search(/\S/) == -1) {
		alert('Please enter city');
		$(city).focus();
		return false;
	}
	if ($F(zip_postal_code).search(/\S/) == -1) {
		alert('Please enter zip or postal code');
		$(zip_postal_code).focus();
		return false;
	}
	if(isZip($F(zip_postal_code))==false) {
		alert('The zip/postal code number you entered is not valid.\r\nPlease enter a zip/postal code number with the format xxxxx or xxxxx-xxxx.');
		$(zip_postal_code).focus();
		return false;
	}
	if ($F(state_province).search(/\S/) == -1) {
		alert('Please enter state or province');
		$(state_province).focus();
		return false;
	}
	if ($F(product_description).search(/\S/) == -1) {
		alert('Please enter product description');
		$(product_description).focus();
		return false;
	}
	if ($F(method_of_contact).search(/\S/) == -1) {
		alert('Please enter method of contact');
		$(method_of_contact).focus();
		return false;
	}
	
	$(pga).value = action;
	 return true;
}
// end of contact_info_validity_check


function Newsletteruser_Validity_Check(action) {
	//alert(action);
	var f = $('frmMain');
	var pga = f['hdnPgaction'];
	
	var user_name = f['user_name'];
	var email_id = f['email_id'];
	
	if ($F(user_name).search(/\S/) == -1) {
		alert('Please enter your name');
		$(user_name).focus();
		return false;
	}
	if ($F(email_id).search(/\S/) == -1) {
		alert('Please enter email');
		$(email_id).focus();
		return false;
	}
	if(emailCheck($F(email_id))==false) {
		alert('Please enter valid email');
		$(email_id).focus();
		return false;
	}
	
	$(pga).value = action;
	 return true;
}




function removeElement(divNum) {
  var d = document.getElementById('myDiv');
  var olddiv = document.getElementById(divNum);
  d.removeChild(olddiv);
}

function addElement() {
  var ni = document.getElementById('myDiv');
  var numi = document.getElementById('theValue');
  var num = (document.getElementById('theValue').value -1)+ 2;
  numi.value = num;
  var newdiv = document.createElement('div');
  var divIdName = 'my'+num+'Div';
  newdiv.setAttribute('id',divIdName);
  newdiv.innerHTML = 'Upload Photo : <input name="GalleryPhotoPath[]" id="'+divIdName+'" type="file" /> <input type="button" name="btnRemove" value="Remove" onclick=\'removeElement("'+divIdName+'")\' />';
  ni.appendChild(newdiv);
  //alert(ni.innerHTML)
}
//end of 
//functions for dynamically remove and add file element 



function Photo_Gallery_Validity_Check(action)
{
	//alert(action);
	var f = $('frmMain');
	var pga = f['hdnPgaction'];
	
	var PhotoGalTitle = f['PhotoGalTitle'];
	var GalleryPhotoPath = f['GalleryPhotoPath'];
		
	if ($F(PhotoGalTitle).search(/\S/) == -1) {
		alert('Please enter photo gallery Title.');
		$(PhotoGalTitle).focus();
		return false;
	}


//	var p_image = document.frmMain.EventPhotoPath.value.trim();
//
//	//alert(p_image);
//	if(p_image != "" ) {
//		//alert("inside image chck.");
//		var image_arr = p_image.split(".");
//		var prod_img = image_arr[1].toUpperCase();
//		if(prod_img!="GIF" && prod_img!="JPG" && prod_img!="JPEG" && prod_img!="PNG" && prod_img!="BMP"){
//			alert("Please upload a .GIF/.JPG/.JPEG/.PNG/.BMP file.");
//			document.frmMain.EventPhotoPath.focus();
//			return false;
//		}
//	}

	$(pga).value = action;
	return true;		
}









function HomeSlideshow_Validity_Check(action) {
	var f = $('frmMain');
	var pga = f['hdnPgaction'];
	var home_title = f['home_title'];
	var home_image = f['home_image'];
	
	if ($F(home_title).search(/\S/) == -1) {
		alert('Image Title can not be left blank');
		$(home_title).focus();
		return false;
	}
	  if(action == 'insert'){
	if ($F(home_image).search(/\S/) == -1) {
		alert('Home slideshow image can not be left blank');
		$(home_image).focus();
		return false;
	}}
	
	if (document.frmMain.home_image.value != '') {
		var d_image = document.frmMain.home_image.value;
		var image_arr = d_image.split(".");
		var dept_image = image_arr[1].toUpperCase();
		if(dept_image!="GIF" && dept_image!="JPG" && dept_image!="JPEG" && dept_image!="PNG" && dept_image!="BMP"){
			alert("Please upload a .GIF/.JPG/.JPEG/.PNG/.BMP file in Slideshow image");
			document.frmMain.home_image.focus();
			return false;
		}
	}
	
	var oEditor = FCKeditorAPI.GetInstance('home_content') ; // Get the editor instance that we want to interact with
	var test_content = oEditor.GetXHTML( true ) ;
	if(test_content=="") {
		alert("Please enter content");
		return false;
	}
	
	
	$(pga).value = action;
    return true;
}  // end of HomeSlideshow_Validity_Check







function Product_Validity_Check(action) {
	var f = $('frmMain');
	var pga = f['hdnPgaction'];
	var product_category = f['product_category'];
	var product = f['product'];
	var product_image = f['product_image'];
	var value = f['value'];
	
	if ($F(product_category).search(/\S/) == -1) {
		alert('Product Category can not be left blank');
		$(product_category).focus();
		return false;
	}
	
	if ($F(product).search(/\S/) == -1) {
		alert('Product Title can not be left blank');
		$(product).focus();
		return false;
	}
	
	
	  if(action == 'insert'){
	if ($F(product_image).search(/\S/) == -1) {
		alert('Product image can not be left blank');
		$(product_image).focus();
		return false;
	}}
	
	if (document.frmMain.product_image.value != '') {
		var d_image = document.frmMain.product_image.value;
		var image_arr = d_image.split(".");
		var dept_image = image_arr[1].toUpperCase();
		if(dept_image!="GIF" && dept_image!="JPG" && dept_image!="JPEG" && dept_image!="PNG" && dept_image!="BMP"){
			alert("Please upload a .GIF/.JPG/.JPEG/.PNG/.BMP file in product image");
			document.frmMain.product_image.focus();
			return false;
		}
	}
	
	var oEditor = FCKeditorAPI.GetInstance('product_description') ; // Get the editor instance that we want to interact with
	var test_content = oEditor.GetXHTML( true ) ;
	if(test_content=="") {
		alert("Please enter product content");
		return false;
	}
	
	if ($F(value).search(/\S/) == -1) {
		alert('Product Value can not be left blank');
		$(value).focus();
		return false;
	}
		
	$(pga).value = action;
    return true;
}  // end of Product_Validity_Check


function Gallery_Validity_Check(action) {
	var f = $('frmMain');
	var pga = f['hdnPgaction'];
	var product_title = f['product_title'];
	var gallery_image = f['gallery_image'];
	
	if ($F(product_title).search(/\S/) == -1) {
		alert('Product Title can not be left blank');
		$(product_title).focus();
		return false;
	}
	
	if(action == 'insert'){
	if ($F(gallery_image).search(/\S/) == -1) {
		alert('Gallery image can not be left blank');
		$(gallery_image).focus();
		return false;
	}}
	
	if (document.frmMain.gallery_image.value != '') {
		var d_image = document.frmMain.gallery_image.value;
		var image_arr = d_image.split(".");
		var dept_image = image_arr[1].toUpperCase();
		
		if(dept_image!="GIF" && dept_image!="JPG" && dept_image!="JPEG" && dept_image!="BMP"){
			alert("Please upload a .GIF/.JPG/.JPEG/.BMP file in gallery image");
			document.frmMain.gallery_image.focus();
			return false;
		}
		
		if(dept_image=="PNG"){
			alert("Please do not select a png image file.");
			document.frmMain.gallery_image.focus();
			return false;
		}
			
	}
	
	$(pga).value = action;
    return true;
}  // end of Product_Validity_Check



function File_Validity_Check(action) {
	var f = $('frmMain');
	var pga = f['hdnPgaction'];
	var file_path = f['file_path'];
	
	
	if(action == 'insert'){
	if ($F(file_path).search(/\S/) == -1) {
		alert('Please upload the file');
		$(file_path).focus();
		return false;
	}}
	
	if (document.frmMain.file_path.value != '') {
		var d_image = document.frmMain.file_path.value;
		var image_arr = d_image.split(".");
		var dept_image = image_arr[1].toUpperCase();
		
		if(dept_image!="PDF" && dept_image!="DOC"){
			alert("Please upload a .PDF/.DOC file only");
			document.frmMain.file_path.focus();
			return false;
		}
		
	
	}
	
	$(pga).value = action;
    return true;
}  // end of Product_Validity_Check

 function Mass_Mail_Validity_Check(action) {
	var f = $('frmMain');
	var pga = f['hdnPgaction'];
	var str = "";
	var is_selected = 0;
	var len = document.frmMain.subscriber.length;
	if(len>0) {
		for(i=0;i<len;i++) {
			if(document.frmMain.subscriber[i].selected==true) {
				str+=document.frmMain.subscriber[i].value+",";
				is_selected = 1;
			}
		}
	}
	else {
		if(document.frmMain.subscriber.selected==true) {
				str+=document.frmMain.subscriber.value+",";
				is_selected = 1;
		}
	}
	
	$(pga).value = action;
	var sel_subscrider = f['sel_subscrider'];
	$(sel_subscrider).value = str;
	//alert($(sel_subscrider).value);
	return true;
}
// end Mass_Mail_Validity_Check


