/* Common JavaScript goes here. */

/**
 * Function Name : trim
 * Description : Used to remove white space from the string
 */

/*function trim(sString) {
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}*/


/**
 * Function Name : isEmpty
 * Return Value : Boolean (true or false) When String empty, return true else false.
 * Description : Used to check the Form Element is null or empty.
 * Parameter Description :
 * 		HtmlElementObject obj = Html Element to validate null or empty.
 *		String errorString = String will be displayed when object value is empty
 *		String errorObjName = Element name to display a Error String, leave blank or pass 'alert' to alert the string.
 *		String defaultValue = while validating, need to consider the default value
 *
 *  Example : 
 	=>  To Display Error in Specific Element ( Div Id )
	 		if(isEmpty(document.form1.firstname, 'First Name is required', 'err_firstname' ) == true ) {
				errorFlag = true;
			}
	
	=>	To make alert for the error 
	
			if(isEmpty(document.form1.firstname, 'First Name is required', '' ) == true ) {
				return false;
			}
		
 *
 *
 */

function isEmpty(obj, errorString, errorObjName, defaultValue ) {
	
	if(obj!='') {
		
		if( trim(obj.value)=='' || obj.value == defaultValue ) {
			
			ShowMessege(errorObjName, errorString);
			
			return true;
			
		} else {
			
			if( errorObjName && errorObjName!='alert' && errorObjName!='') {
				document.getElementById(errorObjName).innerHTML = '';	
			}
			
		}
	}
	return false;
}

/**
 * Function Name : isNumeric
 * Return Value : Boolean (true or false) When value is numeric, return true else false.
 * Description : Used to check the Form Element value is numeric or not.
 * Parameter Description :
 * 		HtmlElementObject obj = Html Element to validate numeric.
 *		String errorString = String will be displayed when object value is numeric
 *		String errorObjName = Element name to display a Error String, leave blank or pass 'alert' to alert the string.
 *
 *  Example : 
 	=>  To Display Error in Specific Element ( Div Id )
	 		if(isNumeric(document.form1.mobileno, 'Mobile number must be numeric', 'err_mobileno' ) == true ) {
				errorFlag = true;
			}
	
	=>	To make alert for the error 
	
			if(isNumeric(document.form1.mobileno, 'Mobile number must be numeric', '' ) == true ) {
				return false;
			}
		
 *
 *
 */
function isNumeric(obj, errorString, errorObjName) {
	
	if(obj!='') {
		var value = obj.value;
		
		if(isNaN(value) ) {
			
			//ShowMessege(errorObjName, errorString);
			
			return true;
			
		} else {
			
			if( errorObjName && errorObjName!='alert' && errorObjName!='') {
				document.getElementById(errorObjName).innerHTML = '';	
			}
			
		}
	}
	return false;
}

/**
 * Function Name : webpage url
 */
function Is_Url(theurl){
	 var tomatch= /[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/
	 if (tomatch.test(theurl))
     {
       //  window.alert("URL OK.");
         return true;
     }
     else
     {
        // window.alert("URL invalid. Try again.");
         return false;
     }
}

/**
 * Function Name : emailValidate
 * Return Value : Boolean (true or false) When value is numeric, return true else false.
 * Description : Used to check the Form Element value is in email format or not.
 */

function emailValidate(email, errorString, errorObjName) {
	
	var emailFilter=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,4}))$/;
	
	if (!(emailFilter.test(email))) {
	     
		ShowMessege(errorObjName, errorString);
		
		return true;
		
	} else {
		
		if( errorObjName && errorObjName!='alert' && errorObjName!='') {
			document.getElementById(errorObjName).innerHTML = '';	
		}
		
	}
	return false;
}

/**
 * Function Name : filenameValidate
 * Return Value : Boolean (true or false) When value is numeric, return true else false.
 * Description : Used to check the Form Element value is in file format or not.
 */
function filenameValidate(filename, errorString, errorObjName) {
	
	var filenameFilter=/^[^\\\/\:\*\?\"\<\>\|\.]+(\.[^\\\/\:\*\?\"\<\>\|\.]+)+$/;
	
	if (!(filenameFilter.test(filename))) {
	     
		ShowMessege(errorObjName, errorString);
		
		return true;
		
	} else {
		
		if( errorObjName && errorObjName!='alert' && errorObjName!='') {
			document.getElementById(errorObjName).innerHTML = '';	
		}
		
	}
	return false;
}

/**
 * Function Name : popupWindow
 * Description : Used to make pop window for specified url with the give hieght and width.
 * Parameter Description :
 * 		String url = Requesting URL.
 *		int width = Width of the window.
 *		int height = Height of the window.
 *		String extraparam = other Parameters.
 */

function popupWindow(url, width, height, extraparam) {
	if(!width){ width = 50; }
	if(!height){ height = 50; }
	if(!extraparam){
		extraparam = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,top=50,left=50';
	}
	window.open( url, 'popupWindow', 'width=' + width + ',height=' + height + ',' + extraparam );
}


/**
 * Function Name : FileTypeValidate
 * Return Value : Boolean (true or false) When value is numeric, return true else false.
 * Description : Used to check the given file name has the valid extention.
 * Parameter Description :
 * 		String filename = Filename to check.
 *		String valid_ext = Valid extensions of filename provide as String.
 *		int height = Height of the window.
 *		String extraparam = other Parameters.
 *		String errorString = String will be displayed when file extension is not valid
 *		String errorObjName = Element name to display a Error String, leave blank or pass 'alert' to alert the string.
 */

function FileTypeValidate(filename, valid_ext, errorString, errorObjName ) {
	
	if(filename!='' && valid_ext && valid_ext != '') {
		
		var fileArr = filename.split(".");
		
		cnfileArr = fileArr.length;
		ext = fileArr[cnfileArr-1];
		
		if(valid_ext.indexOf(ext) == -1){
			
			ShowMessege(errorObjName, errorString);
		
			return true;
			
		} else {
			if( errorObjName && errorObjName!='alert' && errorObjName!='') {
				document.getElementById(errorObjName).innerHTML = '';	
			}
		}
	}
	return false;
}

/**
 * Function Name : compareString
 * Return Value : Boolean (true or false) When value is numeric, return true else false.
 * Description : Used to check the given file name has the valid extention.
 * Parameter Description :
 * 		String filename = Filename to check.
 *		String valid_ext = Valid extensions of filename provide as String.
 *		int height = Height of the window.
 *		String extraparam = other Parameters.
 *		String errorString = String will be displayed when file extension is not valid
 *		String errorObjName = Element name to display a Error String, leave blank or pass 'alert' to alert the string.
 */
function compareString (cStr1, cStr2, errorString, errorObjName) {
	
	if (cStr1 != cStr2){
		
		ShowMessege(errorObjName, errorString);
		
		return true;
		
	} else {
		if( errorObjName && errorObjName!='alert' && errorObjName!='') {
			document.getElementById(errorObjName).innerHTML = '';	
		}
	}
	return false;
}

function ValidationRadioSelectedItem(RadioObj, errorString, errorObjName ) {

	chosen = ""
	len = RadioObj.length
	
	for (i = 0; i <len; i++) {
		if (RadioObj[i].checked) {
			chosen = RadioObj[i].value
		}
	}
	
	if (chosen == "") {
		
		ShowMessege(errorObjName, errorString);
		
		return true;
	//	alert("No Location Chosen")
	} else {
		if( errorObjName && errorObjName!='alert' && errorObjName!='') {
			document.getElementById(errorObjName).innerHTML = '';	
		}
	}
	return false;
}

/**
 * Function Name : redirect
 * @formName: name of the form
 * @redirectToLocation: location(file name) you want to redirect.
 * Description : Redirect to specified filename
 */
function redirect(formName,redirectToLocation)
{
	if(formName != '')
	{
		with(formName)
		{
			document.location =	redirectToLocation;
		}
	}
	else {
		location.href = redirectToLocation;
	}
}

/**
 * Function Name : checkAll
 * @formName: 	name of the form
 * @checkboxid: the id of the checkbox that need to select when clicked on common chkbox (this)
 * @currentObj: object clicking on which the other checkbox specified in "checkboxid" should be selected. Generaly set value as "this"
 * Description: This function will selecte all checkboxes "checkboxid" 
 				when clicked on common checkbox generally located on top of listing used to select all items.
*/
function checkAll(formName, checkboxid, currentObj) {
	var count = formName.elements.length;
	for(i=1;i<count;i++)
	if(formName.elements[i].type=="checkbox" && formName.elements[i].id==checkboxid)
	formName.elements[i].checked=currentObj.checked;
}
//Calender function
function setupCalendar(field,btn) {
	var fieldName = field;
	var btnName = btn;
	Calendar.setup(
		{
			inputField : fieldName,
			button : btn,
			align : "B1",
			singleClick : true
		}
	)
}

function trim(Value)
{
		return Value.replace(/^\s+|\s+$/g, "");
}


function isEmail(str)
{
	var regex = /^[-_.a-z0-9]+@(([-a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
   	
	return regex.test(str);
}

/**
*	FUNCTION TO CHECK THE ALPHANUMERIC VALUSE.
**/
function isAlphaNumeric(alphane)
{
	var inputValue = alphane;
	for(var j=0; j<inputValue.length; j++)
		{
		  var alphaa = inputValue.charAt(j);
		  var hh = alphaa.charCodeAt(0);
		  if((hh > 47 && hh<58) || (hh > 64 && hh<91) || (hh > 96 && hh<123))
		  {}
		else {
             return false;
		  }
 		}
	return true;
}

function isValidProviderNumber(pNumber) {
	var inputPNum = pNumber;
	if(isAlphaNumeric(inputPNum) && inputPNum.length==8) {
		return true;
	} else {
		return false;
	}
}

//Length validation

function isValidLength(givenValue,numlength){
	if(isAlphaNumeric(givenValue) && givenValue == numlength)
	{
	return true;
	} else {
		return false;
	}
	
}

function isValidPhone(phNumber) {
	var inputPh = phNumber;
	var iChars = "0123456789+- )(";
	for (var i = 0; i < inputPh.length; i++) {
	  	if (iChars.indexOf(inputPh.charAt(i)) == -1) {
			return false;
	  	}
	}
	return true;
}

function changePwd(){
	
	var Password = document.getElementById("Password");
	if(trim(Password.value) == ''){
		hideAllPasswordErrors();
		document.getElementById("passwordError").style.display = "inline";
		Password.focus();
		return false;
	}
	if(Password.value.length<4){
		hideAllPasswordErrors();
		document.getElementById("passlengtherror").style.display = "inline";
		Password.focus();
		return false;
	}
	var ConfirmPassword = document.getElementById("ConfirmPassword");
	if(trim(ConfirmPassword.value) == ''){
		hideAllPasswordErrors();
		document.getElementById("confpasswordError").style.display = "inline";
		ConfirmPassword.focus();
		return false;
	}
	var pass = document.changepwd.Password.value;
	var confpass = document.changepwd.ConfirmPassword.value;
	if(pass != confpass){
		hideAllPasswordErrors();
		document.getElementById("confpassinvalidError").style.display = "inline";
		ConfirmPassword.focus();
		return false;
	}
	return true;
}

function hideAllPasswordErrors() {
    document.getElementById("passwordError").style.display = "none";
    document.getElementById("passlengtherror").style.display = "none";
	document.getElementById("confpasswordError").style.display = "none";
	document.getElementById("confpassinvalidError").style.display = "none";
}

function user_personalinfo(){
	
	var Firstname = document.getElementById("Firstname");
	if(trim(Firstname.value) == ''){
		hideAllErrors();
		document.getElementById("firstnameError").style.display = "inline";
		Firstname.focus();
		return false;
	}
	var Lastname = document.getElementById("Lastname");
	if(trim(Lastname.value) == ''){
		hideAllErrors();
		document.getElementById("lastnameError").style.display = "inline";
		Lastname.focus();
		return false;
	}
	var Username = document.getElementById("Username");
	if(trim(Username.value) == ''){
		hideAllErrors();
		document.getElementById("usernameError").style.display = "inline";
		Username.focus();
		return false;
	}
	var Password = document.getElementById("Password");
	if(trim(Password.value) == ''){
		hideAllErrors();
		document.getElementById("passwordError").style.display = "inline";
		Password.focus();
		return false;
	}
	if(Password.value.length<4){
		hideAllErrors();
		document.getElementById("passlengtherror").style.display = "inline";
		Password.focus();
		return false;
	}
	var Email = document.getElementById("Email");
	if(trim(Email.value) == ''){
		hideAllErrors();
		document.getElementById("emailError").style.display = "inline";
		Email.focus();
		return false;
	}
	if(!isEmail(Email.value)){
		hideAllErrors();
		document.getElementById("invalidemailError").style.display = "inline";
		Email.focus();
		return false;
	}
	/*if(document.Frmaddclient.State.selectedIndex == 0 ){
		hideAllErrors();
		document.getElementById("stateError").style.display = "inline";
		document.Frmaddclient.State.focus();
		return false;
	}
	if(document.Frmaddclient.user_type.selectedIndex == 0 ){
		hideAllErrors();
		document.getElementById("usertypeError").style.display = "inline";
		document.Frmaddclient.user_type.focus();
		return false;
	}*/
	
	return true;
}

function hideAllErrors() {
	document.getElementById("firstnameError").style.display = "none";
	document.getElementById("lastnameError").style.display = "none";
	document.getElementById("usernameError").style.display = "none";
    document.getElementById("passwordError").style.display = "none";
    document.getElementById("passlengtherror").style.display = "none";
	document.getElementById("emailError").style.display = "none";
	document.getElementById("invalidemailError").style.display = "none";
	//document.getElementById("stateError").style.display = "none";
	//document.getElementById("usertypeError").style.display = "none";
}

function hideContentErrors(){
	document.getElementById("headingError").style.display = "none";
}

function ValidLogin()
{
    var Username = document.getElementById("LUsername");
	if(trim(Username.value) == ''){
		hideAllLoginErrors();
		document.getElementById("lusernameError").style.display = "inline";
		Username.focus();
		return false;
	}
	var Password = document.getElementById("LPassword");
	if(trim(Password.value) == ''){
		hideAllLoginErrors();
		document.getElementById("lpasswordError").style.display = "inline";
		Password.focus();
		return false;
	}
	return true;
}
function hideAllLoginErrors() {
	document.getElementById("lusernameError").style.display = "none";
    document.getElementById("lpasswordError").style.display = "none";
}

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function isDate(dtStr){
	var daysInotifymonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	//var strMonth=dtStr.substring(0,pos1)
	//var strDay=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=eval(strMonth)
	day=eval(strDay)
	year=eval(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy");
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month");
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInotifymonth[month]){
		//alert("Please enter a valid day");
		return false
	}
	if (strYear.length != 4 || year==0 || year<minotifyyear || year>maxYear){
		var d = new Date();
		var upperlimityear = (eval(d.getFullYear()) > maxYear)? maxYear: d.getFullYear();
		//alert("Please enter a valid 4 digit year between "+minotifyyear+" and "+upperlimityear);
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date");
		return false
	}
//return true
return true
}

function GetDays(toyear, tomonth, today, fromyear, frommonth, fromday)
{
	DDate= new Date(toyear,tomonth-1,today);
	NDate=	new Date(fromyear,frommonth-1,fromday);
	var Days = new String((NDate-DDate)/86400000);
	return Math.floor(Days);
}

function futureDate(ddmmyy) {
  dateParts = ddmmyy.split('/');
  var myDate = new Date(dateParts[2],eval(dateParts[1])-1,dateParts[0]);
  var today  = new Date();  
  if(myDate>today) {
    return true;
  } else {
    return false;
  }
}

function futureMonthYr(monthValue,yearValue) {
   	dt= new Date ();
   	curYr = dt.getFullYear();
   	curMnt = dt.getMonth()+1;
   	tstdt= (curYr*12) + curMnt;
   	entryYR = yearValue;
	entryMN = monthValue; //(frm.eMonth.selectedIndex>0)? frm.eMonth.selectedIndex : 0;
   	entryval= eval(entryYR*12) + eval(entryMN);
   	if ((!isNaN(entryval)) && (entryval>=tstdt)) { return true; } //alert('date is valid');
	else { return false; }
}

//SCHEDULE SEARCH VALIDATION
function showhide(id)
{
	var hideshowid = document.getElementById(id);
	var dispStatus = hideshowid.style.display
    if(dispStatus == 'none')
	{
    	hideshowid.style.display = "inline";
	}
    else
    {
    	hideshowid.style.display = "none";
	}
}
function showhideWithCheckbox(checkboxId, hideshowId)
{
        var checkboxId = document.getElementById(checkboxId);
        var hideshowId = document.getElementById(hideshowId);
        if(checkboxId.checked == true)
        {
                hideshowId.style.display = "inline";
        }
        else
        {
                hideshowId.style.display = "none";
        }
}


//Function for field name that only allowed Digits and Dot...
function DigitsAndDot(FieldName)
{
        if(FieldName.value != "")
        {
                var ValidChars = "0123456789.";
                for (j = 0; j < FieldName.value.length; j++)
                {
                        var Char = FieldName.value.charAt(j);
                        if (ValidChars.indexOf(Char) == -1)
                        {
                                return  false;
                        }
                }
                return true;
        }
}

//Function for field name that only allowed Digits...
function DigitsOnly(FieldName)
{
        if(FieldName.value != '')
        {
                var ValidChars = "0123456789";
                for (j = 0; j < FieldName.value.length; j++)
                {
                        var Char = FieldName.value.charAt(j);
                        if (ValidChars.indexOf(Char) == -1)
                        {
                                return  false;
                        }
                }
        }
}

//Function for field name that only allowed Digits, +, and -(for eg. telephone no: IN IN +91  2221113456  Call   Call )...
function DigitsPlusMinus(FieldName)
{
        if(FieldName.value != "")
        {
                var ValidChars = "0123456789-+( ) ";
                for (j = 0; j < FieldName.value.length; j++)
                {
                        var Char = FieldName.value.charAt(j);
                        if (ValidChars.indexOf(Char) == -1)
                        {
                                return  false;
                        }
                }
                return true;
        }
}



/**************** Developed By Mrunal Soni ************************/

function validate_album(frm){
	if(frm.album_name.value=='' || frm.album_name.value==null){
		alert("Vennligst Enter Albumnavn");
		frm.album_name.focus();
		return false;
	}
}

function validate_shuffler_album(frm){
	if(frm.shuffler_album_name.value=='' || frm.shuffler_album_name.value==null){
		alert("Vennligst fyll stokker Albumnavn");
		frm.shuffler_album_name.focus();
		return false;
	}
}

/****************************************************************/

//Added by Rajesh Thakare for Image Shuffler

function CheckAll(fmobj)
{
	for (var i=0;i<fmobj.elements.length;i++)
	{
		var e = fmobj.elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox') && (!e.disabled))
		{
			e.checked = fmobj.allbox.checked;
		}
	}
}

function fnconfirm()
{	
	var answer = confirm("Er du sikker på at du vil slette dette bildet? Klikk OK for å bekrefte")
	if (answer)
	{
		return true;
	}
	else
	{
		return false;
	}
}
function conform1()
	{	
		var privs = document.getElementsByName("cat_id[]");
		var privschecked = false;
		var a=privs.length;
		for (var i = 0; i < privs.length; i++)
		 {
		  if (privs[i].checked) 
		  {
		   privschecked = true;
		   break;
		  }
		}

		if (!privschecked)
		 {
		  alert('Velg minst ett bilde galleri');
		  return false;
		}
		else
		{
		return fnconfirm();
		}
		return true;
}



//Adddition ends
/****************  Category Validation Developed By Mrunal Soni ****************************/


function validate_category(frm){
	
	if(frm.category_name.value=='' || frm.category_name.value==null){
		alert("Angi Produktgruppenavnet");
		frm.category_name.focus();
		return false;
	}
	if(isNaN(frm.sort_order.value)){
		alert("Sett inn gyldig sorteringsrekkefølge");
		frm.sort_order.focus();
		return false;
	}
}

function change_category_status(){

		if($("input[type=checkbox]:checked").length==0){
			alert("Velg minst én Produktgruppe.");
			return false;
		}
	}
	
	function delete_category(fileName,categoryId,parentId,destination){
	 	 
	$.ajax({
	   type: "POST",
	   url: fileName,
	   data: "category_id="+categoryId+"&action=check_subcategory",
	   success: function(msg){
	   				
	   				if(parseInt(msg)>0){
	   					if(confirm("Er du sikker vil slette denne Produktgruppen? Klikk OK for å bekrefte")){
						     if(confirm("Denne Produktgruppen inneholder underProduktgruppe, Vil du slette alle underProduktgruppe? Klikk OK for å bekrefte")){
						     	   	location.href = fileName+"?category_id="+categoryId+"&action=delete_subcategory"
						     }else{
						     	  	location.href = fileName+"?category_id="+categoryId+"&parent_id="+parentId+"&action=update_subcategory";
						     }
	   					}}else{
	   					if(confirm("Er du sikker vil slette denne Produktgruppen? Klikk OK for å bekrefte")){
	   							location.href = fileName+"?category_id="+categoryId+"&action=delete_category&destination="+destination;
	   					}
	   				}
	   			}
	 });
	 
	return false; 
}

/************  Product Validation Developed By Mrunal Soni ****************************/


function validate_product(frm){
	
	if(frm.product_name.value=='' || frm.product_name.value==null){ 
			alert("Angi Produkternavn");
		frm.product_name.focus();
		return false;
	} 
	
	if (frm.discount_price.value!='' ){ 
		if(isNumeric(frm.discount_price,'Please Number','alert') == true){
			alert('Pris beløpet må være numeriske');
			return false;
		}
	}
	
	if (frm.product_price.value!='' ){ 
		if(isNumeric(frm.product_price,'Please Number','alert') == true){
			alert('Pris beløpet må være numeriske');
			return false;
		}
	}
	return true;
}

function validate_menu(frm){
	
	if(frm.menu_title.value=='' || frm.menu_title.value==null){
		alert("Vennligst angi tittel");
		frm.menu_title.focus();
		return false;
	}
	if(frm.short_order.value=='' || frm.short_order.value==null){
		alert("Vennligst angi menyens sorteringsrekkefølge");
		frm.short_order.focus();
		return false;
	}
	 
	if(frm.short_order.value != '' && frm.short_order.value != null){
		if(isNaN(frm.short_order.value)){
		alert("Vennligst angi et tall som sorteringsrekkefølge");
		frm.short_order.focus();
		return false;
		}
	}
	if(frm.menu_type.value == 3){
		if(frm.product.value=='' || frm.product.value==null){
		alert("Ingen produkter funnet");
		frm.product.focus();
		return false;
		}
	}
	if(frm.menu_type.value == 6){
		
		if(frm.external_link.value=='' || frm.external_link.value==null){
		alert("Fyll inn ekstern link");
		frm.external_link.focus();
		return false;
		}

    var regexp = /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{2}/;
 	if(!regexp.test(frm.external_link.value)){
     alert("Angi gyldig nettadresse (URL).");
        frm.external_link.focus();
        return false;
 	}
	}
	return true;
}

function change_product_status(){

		if($("input[type=checkbox]:checked").length==0){
			alert("Velg minst én Produkter.");
			return false;
		}
	}
	
function delete_product(fileName,productId){
	 	 
	$.ajax({
	   type: "POST",
	   url: fileName,
	   data: "product_id="+productId,
	   success: function(msg){
	   				
	   					if(confirm("Er du sikker på at vil slette dette Produkter?")){
	   							location.href = fileName+"?product_id="+productId+"&action=delete_product";
	   					}
	   				}
	   			
	 });
	 
	return false; 
}

/*************  Delete Album Delvelopd By Mrunal Soni*************************/

function delete_album(fileName,albumId){
	 	 
	$.ajax({
	   type: "POST",
	   url: fileName,
	   data: "album_id="+albumId,
	   success: function(msg){
	   					if(confirm("Er du sikker på at vil slette dette album?")){
	   							location.href = fileName+"?album_id="+albumId+"&action=delete_album";
	   					}
	   				}
	 });
	return false; 
}

function delete_shuffler_album(fileName,shufflerAlbumId){
	 	 
	$.ajax({
	   type: "POST",
	   url: fileName,
	   data: "shuffler_album_id="+shufflerAlbumId,
	   success: function(msg){
	   					if(confirm("Er du sikker på at vil slette dette album?")){
	   							location.href = fileName+"?shuffler_album_id="+shufflerAlbumId+"&action=delete_album";
	   					}
	   				}
	 });
	return false; 
}

/******************************************************************************************/



//Added By Rajesh Thakare for Content Management
function content_info(){
	var Heading = document.getElementById("Heading");	
	if(trim(Heading.value) == ''){
		hideAllContentErrors();
		document.getElementById("headingError").style.display = "inline";
		Heading.focus();
		return false;
	}
	/*
	var newImgVal = document.getElementById("theImg");
	var imgSrc = document.getElementById('mediabank').src;
	alert(imgSrc.indexOf('spacer')+'>>'+newImgVal.value);
	if(imgSrc.indexOf('spacer')>0 && newImgVal.value==''){
		alert('Select image from mediabank or uplaod new image.');
		return false;
	} else {
		Frmaddcontent.submit();
	}*/
	return true;
}

function hideAllContentErrors() {
	document.getElementById("headingError").style.display = "none";
}

//Addition Ends

/******************* For popup window [Developed By Mrunal Soni<mrunal.soni@radixweb.com>]*********************/

function preview_popup(URL) {
	
/*
   There are three arguments that the window.open function takes:

   1. The relative or absolute URL of the webpage to be opened.
   2. The text name for the window.
   3. A long string that contains all the different properties of the window.

   Naming a window is very useful if you want to manipulate it later with JavaScript. However,
   this is beyond the scope of this lesson, and we will instead be focusing on the different properties
   you can set with your brand spanking new JavaScript window. Below are some of the more important properties:

    * dependent - Subwindow closes if the parent window (the window that opened it) closes
    * fullscreen - Display browser in fullscreen mode
    * height - The height of the new window, in pixels
    * width - The width of the new window, in pixels
    * left - Pixel offset from the left side of the screen
    * top - Pixel offset from the top of the screen
    * resizable - Allow the user to resize the window or prevent the user from resizing, currently broken in Firefox.
    * status - Display or don't display the status bar

   Dependent, fullscreen, resizable, and status are all examples of ON/OFF properties. You can either set them equal to zero to turn them off, or set them to one to turn them ON. There is no inbetween setting for these types of properties.

*/	

window.open(URL, "popupWindow", 
"status = 1, height = 500, width = 1500, resizable=0, left =100, top=100, scrollbars=1, toolbar=0, location=0, menubar=0, dependent=1")
}

function validateDesc(){
			
	if (document.getElementById("Description").value == '' ) {
		alert("Vennligst angi detaljer i beskrivelse");
		document.getElementById("Description").focus();
		return false;
	} else{		
		return true;
	}
}	

/***************** Developed By Mrunal Soni  ********************/

function textclear()
{
	document.getElementById("newsletter_mail").value = '';
	document.getElementById("newsletter_mail").focus();
}
function gettext()
{
	var Email = document.getElementById("newsletter_mail");
	if(!Email.value){
		document.getElementById("newsletter_mail").value = 'Nyhetsbrev , Din e-post her';	
	}
}
function frontEmailValidation(){
	var Email = document.getElementById("newsletter_mail");
	if(!isEmail(Email.value)){
		alert("Angi gyldige e-postadresse.");
		Email.focus();
		return false;
	}
}

function validate_NewsLetter(frm){
	with(frm)
	{
	if(newsletter_mail.value=='' || newsletter_mail.value==null){
		alert("Vennligst skriv inn din e-post id");
		newsletter_mail.focus();
		return false;
	}
	if(!isEmail(newsletter_mail.value)){
		alert("Angi gyldige e-postadresse.");
		newsletter_mail.focus();
		return false;
	}
	}
}

function delete_NewsLetter_Id(fileName,Id,Start){
	 	 
	if(confirm("Er du sikker på at vil slette denne e-ID?")){
				location.href = fileName+"?NewsLetterMailId="+Id+"&action=delete&startRow="+Start;
		}
	
	return false; 
}
function validate_Unsubscribe(frm){
	with(frm)
	{
	if(unsubscribe.value=='' || unsubscribe.value==null){
		alert("Vennligst skriv inn din e-post id");
		unsubscribe.focus();
		return false;
	}
	if(!isEmail(unsubscribe.value)){
		alert("Angi gyldige e-postadresse.");
		unsubscribe.focus();
		return false;
	}
	}
}

/******************************************************************/

/*--------------Developed by Rajesh Thakare-----------------------*/
function BrowseServer( startupPath, functionData)
{
	// You can use the "CKFinder" class to render CKFinder in a page:
	


	var finder = new CKFinder() ;
	
	// The path for the installation of CKFinder (default = "/ckfinder/").
	finder.BasePath = '/lib/ckeditor/ckfinder' ;
	
	//Startup path in a form: "Type:/path/to/directory/"
	finder.StartupPath = startupPath ;
	//finder.Config['fileUpload'] = false;
	// Name of a function which is called when a file is selected in CKFinder.
	finder.SelectFunction = SetFileField ;
	//finder.fileUpload = false
	// Additional data to be passed to the SelectFunction in a second argument.
	// We'll use this feature to pass the Id of a field that will be updated.
	finder.SelectFunctionData = functionData ;
	
	// Name of a function which is called when a thumbnail is selected in CKFinder.
	finder.SelectThumbnailFunction = ShowThumbnails ;

	
	// Launch CKFinder
	finder.Popup() ;
}
function ShowThumbnails( fileUrl, data )
{
	var sFileName = decodeURIComponent( fileUrl.replace( /^.*[\/\\]/g, '' ) ) ;
	document.getElementById( 'thumbnails' ).innerHTML += 
			'<div class="thumb">' +
				'<img src="' + fileUrl + '" />' +
				'<div class="caption">' +
					'<a href="' + data["fileUrl"] + '" target="_blank">' + sFileName + '</a> (' + data["fileSize"] + 'KB)' +
				'</div>' +
			'</div>' ;

	document.getElementById( 'preview' ).style.display = "";
	// It is not required to return any value.
	// When false is returned, CKFinder will not close automatically.
	return false;
}
/*--------------Ends-----------------------*/
/*
* For Check/Uncheck checkbox array 
* chkUncheck(document.FormName.elements['Checkbox[]']); // Checkbox = Checkbox name whcih you defined as array
*/
function chkUncheck(chkStatus,chk)
{    
   // alert(chk.length);return false;
    if(chkStatus == true){
        if(chk.length == undefined) {
            chk.checked = true ;
        }else {
            for (i = 0; i < chk.length; i++)
            chk[i].checked = true ;
        }
    }
    else{
        if(chk.length == undefined) {
            chk.checked = false ;
        }else {
            for (i = 0; i < chk.length; i++)
            chk[i].checked = false ;
        }
    }
}
