function checkCombo(cmbObject,defaultValue,msgDisplay)
{
var strData;
strData=cmbObject.value;
//alert("Default Value : " + defaultValue);
if(strData == defaultValue)
{
	alert("Please Select Appropriate Option from the  Following Field : " + msgDisplay);
	cmbObject.focus();
	return false;
}
}
function checkStrLen(txtObj,minLength,MaxLength,msgDisplay)
{
var strData;
strData=txtObj.value;
//alert(strData.length);
if(strData.length < Number(minLength))
{
	alert("Please Enter Valid Value In The Following Field : " + msgDisplay);
	txtObj.focus();
	return false;
}
if(strData.length > Number(MaxLength))
{
	alert("Please Enter Value Lesser Than " + MaxLength +" In The Following Field : " + msgDisplay);
	txtObj.focus();
	return false;

}
}
function selectAllCB(objChk,strFormName,strMainId) {
	var frm= gGetElementById(strFormName);
	var ele=frm.elements;
	for(var i=0;i<ele.length;i++)
	{
		if(ele[i].type == "checkbox") {
			if(ele[i].id==strMainId) {
				ele[i].checked=objChk.checked;
			}
		}
	}
}

// cross platform equiv. to document.getElementById
function gGetElementById(s) {
  var o = (document.getElementById ? document.getElementById(s) : document.all[s]);
  return o == null ? false : o;
}

function getCheckBoxSelectCount(strFormName,strMainId) {
	//strMainId = checkboxid
	var frm= gGetElementById(strFormName);
	var ele=frm.elements;
	var cnt=0;
	for(var i=0;i<ele.length;i++)
	{
		if(ele[i].type == "checkbox") {
			if(ele[i].id==strMainId) {
				if(ele[i].checked) {
					cnt=cnt+1;
				}
			}
		}
	}
	return(cnt);
}

function getCheckBoxSelectedValues(strFormName,strMainId) {
	var frm= gGetElementById(strFormName);
	var ele=frm.elements;
	var cnt=0;
	var ans="";
	for(var i=0;i<ele.length;i++)
	{
		if(ele[i].type == "checkbox") {
			if(ele[i].id==strMainId) {
				if(ele[i].checked) {
					if(ans=="") 
						ans=ele[i].value;
					else
						ans=ans + "," + ele[i].value;
				}
			}
		}
	}

	return(ans);
}

function actions(strFormName,strAction,strMainId,objCmb) {

	//strAction = CMBNAME
	//objCmb.value = selectvalue
	var ans;
	var actionText;
	var frm= gGetElementById(strFormName);
	var cmbAction;
	var cnt;
	if(objCmb.value!="0" && objCmb.value!="-") {
		ans=getCheckBoxSelectedValues(strFormName,strMainId);
		if(ans != "") {
			var objIds;
			objIds=gGetElementById(strMainId + "s");
			if(objCmb.value.indexOf("*S") > 0){
				cnt=getCheckBoxSelectCount(strFormName,strMainId);
				if(cnt==1) {
					objIds.value=ans;
					frm.submit();
				} else {
					alert("Please Select Single Record.");
					objCmb.value=0;
					return false;
				}
			} else if(objCmb.value.indexOf("*M") > 0){
				objIds.value=ans;
				frm.submit();
			} else {
				actionText=gGetElementById(strAction).options[gGetElementById(strAction).selectedIndex].text;
				if(confirm("Are you sure to perform " + actionText + " Action on selected records ?")) {
					objIds.value=ans;
					frm.submit();
				} else {
					objCmb.value=0;
					return false;
				}
			}
		} else {
			alert("You need to some records.");
			objCmb.value=0;
			return false;
		}
	} else {
		objCmb.value=0;
		return false;
	}
}

function resetAndSubmit(strFormName) {
	var frm= gGetElementById(strFormName);
	var ele=frm.elements;
	for(var i=0;i<ele.length;i++)
	{
		if(ele[i].type == "hidden" || ele[i].type == "text") {
			ele[i].value="";
		} else if(ele[i].type == "select-one") {
			ele[i].options[0].selected=true;
		} else {
			
		}
	}
 	return true;
}

function getFront(mainStr,searchStr){
	foundOffset = mainStr.indexOf(searchStr)
	if (foundOffset == -1) {
		return null
	}
	return mainStr.substring(0,foundOffset)
}

// extract back end of string after searchString
function getEnd(mainStr,searchStr) {
	foundOffset = mainStr.indexOf(searchStr)
	if (foundOffset == -1) {
		return null
	}
	return mainStr.substring(foundOffset+searchStr.length,mainStr.length)
}

// insert insertString immediately before searchString
function insertString(mainStr,searchStr,insertStr) {
	var front = getFront(mainStr,searchStr)
	var end = getEnd(mainStr,searchStr)
	if (front != null && end != null) {
		return front + insertStr + searchStr + end
	}
	return null
}

// remove deleteString
function deleteString(mainStr,deleteStr) {
	return replaceString(mainStr,deleteStr,"")
}

// replace searchString with replaceString
function replaceString(mainStr,searchStr,replaceStr) {
	var front = getFront(mainStr,searchStr)
	var end = getEnd(mainStr,searchStr)
	if (front != null && end != null) {
		return front + replaceStr + end
	}
	return null
}
function edCmdImage(strCommand,opType) {
//opType=1 = Enable
//opType=2 = Disable
	var Img;
	var temp;
	var strReplace;
	var strReplaceBy;
	Img=gGetElementById("cmd"+strCommand);
	temp=Img.src;
	
	if(getFront(temp,strCommand + "_o.jpg")) {
		strReplace=strCommand + "_o.jpg";
	} else {
		strReplace=strCommand + "_d.jpg";
	}
	
	if(opType=="1") {
		strReplaceBy=strCommand + "_o.jpg";
	} else {
		strReplaceBy=strCommand + "_d.jpg";
	}
	temp=replaceString(temp,strReplace,strReplaceBy);
	Img.src=temp;
}
function clickCmdImgs(opType,baseURL,strFormName,cbId) {
	var cnt;
	var a;
	switch(opType) {
		case "add":
			a=gGetElementById("addLink"+strFormName);
			window.location=a;
			break;
		case "edit":
			a=gGetElementById("editLink"+strFormName);
			a=a + getCheckBoxSelectedValues(strFormName,cbId);
			cnt=getCheckBoxSelectCount(strFormName,cbId)		
			if(cnt==1) {
				window.location=a;
			}
			break;
		case "delete":
			a=gGetElementById("deleteLink"+strFormName);
			a=a + getCheckBoxSelectedValues(strFormName,cbId);
			cnt=getCheckBoxSelectCount(strFormName,cbId)
			if(cnt>0) {
				window.location=a;
			}
			break;
			
		case "compose_msg":
			/*a=gGetElementById("sendLink"+strFormName);
			a=a + getCheckBoxSelectedValues(strFormName,cbId);
			cnt=getCheckBoxSelectCount(strFormName,cbId)*/
			a=gGetElementById("sendLink"+strFormName);
			a=a + getCheckBoxSelectedValues(strFormName,cbId);
			window.location=a;
			break;
			/*if(cnt>0) {
					window.location=a;
				
			}else{
					alert("Please select record to send message");
			}
			break;*/
	}
	return false;
}
function changeCmdImgs(baseURL,strFormName,cbId) {
	var cnt;
	cnt=getCheckBoxSelectCount(strFormName,cbId)
	if(cnt==1) {
		edCmdImage("edit",1);
	} else {
		edCmdImage("edit",0);
	}
	
	if(cnt>0) {
		edCmdImage("delete",1);
	} else {
		edCmdImage("delete",0);
	}
	/*if(baseURL=='admin/subscribers'){
	/*if(cnt>0) {
		edCmdImage("send_msg",1);
	} else {
		edCmdImage("send_msg",0);
	}/*
	}*/
}
function setAddOther(strFieldName) {
		var field;
		field=gGetElementById(strFieldName);
		field.value="1";
		return true;
}
function submitDelete(strFormName,cbId) {
var cnt;
var ids;
cnt=getCheckBoxSelectCount(strFormName,cbId);
if(cnt > 0 ) {
	ids=gGetElementById("deleteIds");
	ids.value=getCheckBoxSelectedValues(strFormName,cbId);
	return true;
} else {
	alert("You need to select the Records to Delete.");
	return false;
}
		
}

function setUrl(){
	var ele;
	ele=gGetElementById("name");
	ele1=gGetElementById("url");
	ele1.value=ele.value;
//	alert(ele.value);
}

function getComboValue(){
		var ele;
		ele=gGetElementById("pa");
		ele1=gGetElementById("spa");
		ele2=gGetElementById("province");
		ele3=gGetElementById("city");
		List=Array();
		List['pa']=ele.value;
		List['spa']=ele1.value;
		List['province']=ele2.value;
		List['city']=ele3.value;
		ele5=gGetElementById("list");
		ele5.value=List['pa']+","+List['spa'];
		return true;
}

function search_term(){
		var ele,val;
		ele=gGetElementById("txtTerm");
		if(ele.value=='e.g. toronto; civil lawyer;'){
			ele.value='';
		}
}
function set_same_value(){
	ele=gGetElementById("txtTerm");
	val=ele.value;
	if(val==''){
		ele.value='e.g. toronto; civil lawyer;';
	}
}

function check_combo_exist(){
	ids=Array();
	ids[0]='city_search';
	ids[1]='spa_search';
	ids[2]='city_search_1';
	ids[3]='spa_search_1';
	for(i=0;i<ids.length;i++){
		ele=gGetElementById(ids[i]);
		if(ele){
			Element.hide(ids[i]);
		}
	}
	return true;
}


function checkForPresenceInSelect2(optVal, text, selList) {
 for (i = 0; i < selList.length; i++) {
   if (selList.options[i].value == optVal) return true;
   if (selList.options[i].text == text) return true;
 }
 return false;
}
// Logic for moving a multi-select from element1 to element2
function gGetElementById(s) {
  var o = (document.getElementById ? document.getElementById(s) : document.all[s]);
  return o == null ? false : o;
}
function selectAllOptions(oblCmb)
{
var len = oblCmb.length;
for (var i = 0; i < len; ++i) {
 	 oblCmb.options[i].selected = true;
   }
}

function one2two(element1, element2) {
 var memberList = gGetElementById(element1);
 var selectedList = gGetElementById(element2);
 var len = memberList.length;

 // Ignore any selections that are made to "------"
 for (var i = 0; i < len; ++i) {
   if (memberList.options[i].selected == true) {
	 memberList.options[i].selected = false;
	 if (memberList.options[i].text == "------") {
	   continue;
	 }
	 
	 if (checkForPresenceInSelect2(memberList.options[i].value, memberList.options[i].text, selectedList) == false) {

	   selectedList.options[selectedList.length] = new Option(memberList.options[i].text, memberList.options[i].value);
	   
	 }
   }
 }
}

// moving a multi-select from element2 to element1.
// Actually this assumes that the values being moved are
// already present in element1 and ends up deleting
// the selected values in element2.
function two2one(element1, element2) {
 var selectedList = gGetElementById(element2);
 for (i = selectedList.length -1; i >= 0; i--) {
   if (selectedList.options[i].selected == true) {
	 selectedList.options[i] = null;
   }
 }
}

function one2twoSingle(element1, element2) {
 var memberList = gGetElementById(element1);
 var selectedList = gGetElementById(element2);
 var len = memberList.length;
 for (var i = 0; i < len; i++) {
    if (memberList.options[i].selected == true) {
		memberList.options[i].selected = false;
	 if (checkForPresenceInSelect2(memberList.options[i].value, memberList.options[i].text, selectedList) == false) {
	   selectedList.options[selectedList.length] = new Option(memberList.options[i].text, memberList.options[i].value);
	 }
	}
 }
}

function two2oneSingle(element1, element2) {
	var selectedList = gGetElementById(element2);
	for (i = selectedList.length -1; i >= 0; i--) {
		if(selectedList.options[i].selected==true) {
			selectedList.options[i].selected=false;
			selectedList.options[i] = null;
		}
	}
}

function setTextarea() {
		ele=gGetElementById('editor_Html Text');
		ele1=gGetElementById('editor_Simple Text');
		simed=gGetElementById('simTextEd1');
		htmed=gGetElementById('htmlTextEd1');
		if(ele.checked){	
			simed.style.display='none';
			htmed.style.display='';
			
			/*document.getElementById('simTextEd').style.display='none';
			document.getElementById('htmlTextEd').style.display='';*/
		}
		else if(ele1.checked){
			htmed.style.display='none';			
			simed.style.display='';
		}
}

function SelectList() {
		ele=gGetElementById('radio_Category');
		ele1=gGetElementById('radio_Product');
		ele2=gGetElementById('radio_All Products');
		
		cat=gGetElementById('Category');
		pro=gGetElementById('Product');
		pList=gGetElementById('firstListProduct');
		pList2=gGetElementById('firstProduct');
		cList=gGetElementById('firstListCategory');
		cList2=gGetElementById('firstCategory');
		
		/*if(ele2.checked){
			cList='';
		selectAllOptions(pList);
			one2two('firstListProduct', 'firstProduct');
		}else{
			selectAllOptions(pList2);
			two2one('firstListProduct', 'firstProduct');	
			
		}*/
		
		if(ele1.checked){
			cat.style.display='none';
			pro.style.display='';
			pList='';
			selectAllOptions(cList2);
			two2one('firstListCategory', 'firstCategory');
			/*
			document.getElementById('htmlTextEd').className="showme"; 
			document.getElementById('simTextEd').className="noshow";
			*/
		}
		else if(ele.checked){
			cList='';
			selectAllOptions(pList2);
			two2one('firstListProduct', 'firstProduct');
			cat.style.display='';
			pro.style.display='none';
			/*
			document.getElementById('htmlTextEd').className="noshow"; 
			document.getElementById('simTextEd').className="showme";
			*/
		}else{
			cat.style.display='none';
			pro.style.display='none';
		}
}
function SelectComboOption()
{
	
	var concmbdiv=gGetElementById('CountryCmb');	
	var condiv=gGetElementById('CountryList');		
	var prodiv=gGetElementById('ProvinceList');		
	var cn=gGetElementById('radio_Country');
	var pr=gGetElementById('radio_Province');	
	var concmb=gGetElementById('CountryCmb');	 
	var con=gGetElementById('Country');
	var pro=gGetElementById('Province');
	var conList=gGetElementById('firstListCountry');
	var conList2=gGetElementById('firstCountry');
	
	if(cn.checked){//Country Checked
		condiv.style.display='';	
		concmbdiv.style.display='none';
		prodiv.style.display='none';		
		pro='';
		concmb ='';
	}else if(pr.checked){ //Province Checked
		condiv.style.display='none';		
		concmbdiv.style.display='';
		prodiv.style.display='';		
		con='';
	selectAllOptions(conList2);
	two2one('firstListCountry', 'firstCountry');
	}else{
		concmbdiv.style.display='none';
		prodiv.style.display='none';
	}
}
function checkPwds()
{
	var password;
	var confirm_password;
	password=gGetElementById("password");
	confirm_password=gGetElementById("confirm_password");
if(password.value!='' && confirm_password.value!='')
{
	if(confirm_password.value!=password.value)
	{
			alert("Passwords do not match");
			password.value='';
			confirm_password.value='';
			password.focus();
			return false;
	}
}
return;	
}
function checkEmail(objTxt) {
	var GoodChars = "@_-.:/ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
	var UpperEmail = objTxt.value.toUpperCase()
	var ValidChars = true;
	
	for (tfCharNum = 0; tfCharNum > objTxt.value.length; tfCharNum++) {
		Char = UpperEmail.charAt(tfCharNum);
		for (gcCharNum = 0;  gcCharNum < GoodChars.length;  gcCharNum++) {
				 if (Char == GoodChars.charAt(gcCharNum))
			     break;
		}
				 
		if (gcCharNum == GoodChars.length)   {
		     ValidChars = false;
		     break;
   		}
	}
	
	if (!ValidChars || objTxt.value.length < 7 || 
		objTxt.value.indexOf("@") == "-1" ||
		objTxt.value.indexOf(".") == "-1" || 
		objTxt.value.indexOf("..") != "-1" || 
		objTxt.value.indexOf("@.") != "-1" || 
		objTxt.value.indexOf("@:") != "-1" || 
		objTxt.value.indexOf("@/") != "-1" || 
		objTxt.value.indexOf("@-") != "-1" || 
		objTxt.value.indexOf("@_") != "-1" || 
		objTxt.value.indexOf(".@") != "-1" || 
		objTxt.value.indexOf(":@") != "-1" || 
		objTxt.value.indexOf("/@") != "-1" || 
		objTxt.value.indexOf("-@") != "-1" || 
		objTxt.value.indexOf("_@") != "-1" || 
		objTxt.value.indexOf("@") != objTxt.value.lastIndexOf("@")) {
		objTxt.focus();
			return (false);
	}
	return (true);
}
function validate_frm(){
	var name;
	var email;
	email=gGetElementById("email");
	if(!checkEmail(email)){
		email.focus();
		alert("Please Enter Proper Value For Email");
		return false;
	}
	return;
}
function checkPwds(){
	var password;
	var confirm_password;
password=gGetElementById("c_password");
confirm_password=gGetElementById("confirm_password");
if(password.value!='' && confirm_password.value!=''){
	if(confirm_password.value!=password.value){
			alert("Passwords do not match");
			password.value='';
			confirm_password.value='';
			password.focus();
			return false;
	}
}
return;	
}
function checkQty(eleId)
{
	if(eleId.value=="")
	{
		alert("Enter Quantity");
		eleId.focus();
		return false;
	}	
}
/* added by tejal on 11/9/2008 */
function checkInputs(){
	var name;
	var email;
	email=gGetElementById("rEmail");
	name=gGetElementById("rName");
	if(checkStrLen(name,1,50,"Recepient Name")==false){
		return false;
	}
	if(!checkEmail(email)){
		email.focus();
		alert("Please Enter Proper Value For Recepient Email");
		return false;
	}
return;
}
function CheckEmailValue(){
ele=gGetElementById('users_100');
email=gGetElementById('name');
subject=gGetElementById('subject');
from=gGetElementById('from');
html_txt=gGetElementById('htmlText');
sim_txt=gGetElementById('simText');
//if(ele.selected
if(ele.name=='data[NewsLetter][users]' && ele.value==100 && ele.checked==true ){
	if(email.value==''){
			alert("Please Specify Email Id(S)");
			email.focus();
			return false;
	}
}
if(subject.value==''){
			alert("Please Specify Value for - Email Subject");
			subject.focus();
			return false;
}
if(from.value==''){
			alert("Please Specify Value for - From");
			from.focus();
			return false;
}
	return;
}


/*  ---------- */
/*function CheckTemp(frm)
{
	alert(frm.action);
}*/






