function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
		window.onload = func;
	else
	{
		window.onload = function()
		{
			if (oldonload) oldonload();
			func();
		}
	}
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct
	expires time, the current script below will set
	it for x number of days, to make it for hours,
	delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
	expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	document.cookie = name + "=" +escape( value ) +
	( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
	( ( path ) ? ";path=" + path : "" ) +
	( ( domain ) ? ";domain=" + domain : "" ) +
	( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain )
{
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

// this function gets the cookie, if it exists
function Get_Cookie( name )
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
function checkPhone(str)
{
	rePhoneNumber = new RegExp(/^[0-9]{0,3}\s?\-?\s?[0-9]{7,10}$/);
	if (!rePhoneNumber.test(str))
		return false;

	return true;

}
function checkmobilePhone(str)
{
	rePhoneNumber = new RegExp(/^[0-9]{0,3}\s?\-?\s?[0-9]{7,10}$/);
	if (!rePhoneNumber.test(str))
		return false;
	var kidomet=str.substr(0,3);
	if(kidomet!="050" && kidomet!="052" && kidomet!="054" && kidomet!="057")
	{
		return false;
	}
	return true;

}
function checkEmail(str) {
///// function for validating email address
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)

		if (str.indexOf(at)==-1){
		    return false
		} else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		    return false
		} else 	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		} else  if (str.indexOf(at,(lat+1))!=-1){
		    return false
		} else 	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   return false
		} else  if (str.indexOf(dot,(lat+2))==-1){
		    return false
		} else if (str.indexOf(" ")!=-1){
		     return false
		} else {
 		 	return true
 		}
}

function getFlashMovieObject(movieName)
{
	if (document.embeds && document.embeds[movieName])
		return document.embeds[movieName];
	if (window.document[movieName])
		return window.document[movieName];
	if (navigator.appName.indexOf("Microsoft Internet")==1)
		return document.getElementById(movieName);
}



function getHTTPObject()
{
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	try { return new XMLHttpRequest(); } catch(e) {}
	alert("XMLHttpRequest not supported");
	return null;
 }

function LoadHTML(url)
{

	var xmlHttp = getHTTPObject();
	xmlHttp.open("GET",url, false);
	xmlHttp.onreadystatechange = function()
	{
		   if (xmlHttp.readyState != 4)  { return; }
		   var serverResponse = xmlHttp.responseText;

	}
	xmlHttp.send(null);
	return xmlHttp.responseText;
}
function LoadXML(url)
{
	var xmlHttp = getHTTPObject();
	xmlHttp.open("GET",url, false);
	xmlHttp.onreadystatechange = function()
	{
		   if (xmlHttp.readyState != 4)  { return; }
		   var serverResponse = xmlHttp.responseText;
	};
	xmlHttp.send(null);
	return xmlHttp.responseXML.documentElement;
}

function PostXML(url,params)
{
	xmlHttp = false;
	// branch for native XMLHttpRequest object
	if(window.XMLHttpRequest && !(window.ActiveXObject))
	{
		try {
			xmlHttp = new XMLHttpRequest();
		} catch(e) {
			xmlHttp = false;
		}
		// branch for IE/Windows ActiveX version
	} else if(window.ActiveXObject)
	{
		try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch(e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
			} catch(e) {
				xmlHttp = false;
			}
		}
	}

	if (xmlHttp)
	{
		xmlHttp.open( "POST", url, false );
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
		return xmlHttp.responseXML.documentElement;
	}
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.-, ";
   var IsNumber=true;
   var Char;


   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;
 }

function trim(strText) {
/// TRIM STRING FUNCTION
    // this will get rid of leading spaces
    while (strText.substring(0,1) == ' ')
        strText = strText.substring(1, strText.length);
    // this will get rid of trailing spaces
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);
   return strText;
}

function escapeString(sString)
{
// DETECT WHAT TO PUT STRING IN FOR HTML FORM ( ' OR " ) DEPANDING ON STRING CONTENTS
	if (sString.indexOf("'") == -1)
		valSep = "'";
	else
		valSep = '"';
	return valSep+sString+valSep;
}

function replaceSubstring(inputString, fromString, toString) {
 // GOES THROUGH THE INPUTSTRING AND REPLACES EVERY OCCURRENCE OF FROMSTRING WITH TOSTRING
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
}

function popupWin(popUrl, width, height)
{
	if (!navigator.appName.indexOf("Microsoft")) width+=20;
	height+=5;
	topVar=((screen.height / 2)-(height/2));
	leftVar=((screen.width / 2)-(width/2));
	window.open(popUrl, "PopUp", "height="+height+", width="+width+", top="+topVar+", left="+leftVar+", scrollbars=yes, status=no, location=no, resize=yes, menubar=no, titlebar=no, toolbar=no");
}

function focusField(f, def)
{
	if (f.value == def) f.value = "";
}

function blurField(f, def)
{
	f.value = trim(f.value);
	if (f.value == "") f.value = def;
}

function getFileExtension(filename)
{
	if( filename.length == 0 ) return "";
	var dot = filename.lastIndexOf(".");
	if( dot == -1 ) return "";
	var extension = filename.substr(dot,filename.length);
	return extension
}

function fix_external_links() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");

	var basicPattern = new RegExp('^(http:\/\/|https:\/\/)');
	var pattern = new RegExp('^(http:\/\/|https:\/\/)'+location.hostname);

	for (var i = 0; i < anchors.length; i++)
	{
		var anchor = anchors[i];
		if (anchor.getAttribute("rel") && anchor.getAttribute("rel") == "external") {
			anchor.target = "_blank";
		}
		else if (getFileExtension(anchor.href) == ".pdf") {
			anchor.target = "_blank";
		}
		else if (!anchor.href.match(basicPattern))  // this is for links such as "javascript" or "#" which do not include http or https at all !!
			continue;
		else if (!anchor.href.match(pattern) && !anchor.getAttribute("rel") || (anchor.getAttribute("rel") && anchor.getAttribute("rel") != "ibox")) {
			anchor.target = "_blank";
		}
	}
}

function clearfld(curinput)
{
	if ((curinput.value==email_t))
	{
		curinput.value="";
	}
	
}


function chkfld(curinput)
{
	if (curinput.value=="" && curinput.name=="email_field")
	{
		curinput.value=email_t;
	}
}

function clearfldsrc(curinput)
{
	if ((curinput.value==search_t))
	{
		curinput.value="";
	}
	
}


function chkfldsrc(curinput)
{
	if (curinput.value=="" && curinput.name=="Sstr")
	{
		curinput.value=search_t;
	}
}

/*
	Tyco join mailing list JAVASCRIPT settings and functions
	Author: Eytan Chen
	Published: January 2008
	all rights reserved to Tyco Interactive ltd.
	http://www.tyco.co.il
*/

function submit_joinML(email_field){
	if (email_field.value==""){
	 	alert (_joinML_empty);
	 	email_field.focus();
	} else if (!checkEmail(email_field.value)){
	 	alert (_joinML_invalid);
	 	email_field.focus();
	} else {
		var url = _base+"/tyco_joinML.ajax.php?joinML_email="+email_field.value;
		var xml = LoadXML(url);
		if(xml != null)
		{
			var response = xml.getElementsByTagName('rsp_stat')[0].firstChild.data;
			if (response=="ok")
			{
				email_field.value="";
				alert (_joinML_confirm);
			}
		}
	}
	return false;
}

function checkEmail(str) {
///// function for validating email address
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)

		if (str.indexOf(at)==-1){
		    return false
		} else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		    return false
		} else 	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		} else  if (str.indexOf(at,(lat+1))!=-1){
		    return false
		} else 	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   return false
		} else  if (str.indexOf(dot,(lat+2))==-1){
		    return false
		} else if (str.indexOf(" ")!=-1){
		     return false
		} else {
 		 	return true
 		}
}

function getHTTPObject()
{
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
	try { return new XMLHttpRequest(); } catch(e) {}
	alert("XMLHttpRequest not supported");
	return null;
 }

function LoadXML(url)
{
	var xmlHttp = getHTTPObject();
	xmlHttp.open("GET",url, false);
	xmlHttp.onreadystatechange = function()
	{
		   if (xmlHttp.readyState != 4)  { return; }
		   var serverResponse = xmlHttp.responseText;
	};
	xmlHttp.send(null);
	return xmlHttp.responseXML.documentElement;
}

function submitContact(f)
{
	// disable submit button and change its class
	submitButton = document.getElementById("submitForm");
	submitButton.disabled = true;

	ReqFields = new Array("contact_fName","contact_lName","contact_phone","contact_email");
	for (i=0;i<ReqFields.length; i++)
	{
		fieldName = ReqFields[i];
		if (trim(f[fieldName].value) == "")
		{
			cMessage = eval("_"+fieldName);
			alert(cMessage);
			f[fieldName].focus();
			submitButton.disabled = false;
			return false;
		}

		if (fieldName == "contact_email" && !checkEmail(f[fieldName].value))
		{
			alert(_contact_emailInvalid);
			f[fieldName].focus();
			submitButton.disabled = false;
			return false;
		}

		if (fieldName == "contact_phone" && !checkPhone(f[fieldName].value))
		{
			alert(_contact_phoneInvalid);
			f[fieldName].focus();
			submitButton.disabled = false;
			return false;
		}

	}

	if (confirm(_contact_confirm))
	{
		advAJAX.submit(f, {
		    onSuccess : function(obj) {
		    		if (obj.responseText == "success")
		    		{
		    			alert (_contact_success);
		    			f.reset();
		    			submitButton.disabled = false;
		    		}
		    		else
		    		{
		    			alert (_contact_fail);
		    			submitButton.disabled = false;
		    		}
		    }
		});
		return false;
	}

	submitButton.disabled = false;
	return false;
}


//open meesage smart
function openmessage(c_href)
{
	avalue=c_href.className;
	container = document.getElementById("faq_mc");
	cAnswer = c_href.nextSibling;
	cDisplay = cAnswer.style.display;
	for (i=0; i<container.childNodes.length; i++)
	{
		cElement = container.childNodes[i];
		if (cElement.className == "faq_answer")
			cElement.style.display = "none";
			/*if (cElement.className == "opened")
			cElement.className = "open";*/
	}
	/*if(avalue=="open")
	{
		c_href.className="opened";
	}
	else
	{
		c_href.className="open";
	}*/
	cAnswer.style.display = (cDisplay == "block" ) ? "none" : "block";
	return false;
}

function changeframe(obj)
{
	iBox.hide();
	url = obj.href;
	iBox.showURL(url,"", {width: 410}, true);
	return false;
}

function openBothframe(obj)
{
	//iBox.hide();
	url = obj.href;
	iBox.showURL(url,"", {width: 410}, true);
	return false;
}

function addtocart(id,type)
{
	var url = _base+"/cart_functions.php?id="+id+"&type="+type;
	var xml = LoadHTML(url);
	if(xml == null)
	{
		alert(_itemadderror);
	}
	//window.location.href=_base+"/ShoppingCart.php";
	_session = Get_Cookie("PHPSESSID");
	window.location.href = _shoppingCart+"?curSessionID="+_session;
	return false;
}

/**
printing from an lightbox light element
Liran Oz
**/

var __ibpdest = null, __ibptimer;
function iboxPrint(srcId, destId) {    
    var src = $("#" + srcId);
    var dest = $("#" + destId);
    if (!src || !dest)
        return false;
        
    if (__ibptimer != null) {
        clearTimeout(__ibptimer);
        __ibptimer = null;
    }
        
    //clear everything in dest    
    dest.empty();
    //copy data from src to dest
    dest.append(src.clone());
    //print the window     
    window.print();
    __ibpdest = dest;
    __ibptimer = setTimeout("iboxPrintClear()", 15000);
}

function iboxPrintClear() {
    if  (__ibpdest == null || __ibptimer == null)
        return;
    
    __ibptimer = null;    
    __ibpdest.empty();
    //restore everything
    __ibpdest.empty();
}

function hideFlash() {
    $("#f_flash_carousel").css("visibility", "hidden");
}

function showFlash() {
    $("#f_flash_carousel").css("visibility", "visible");
}

function myIbox(url, myWidth) {
	stopButton();
	iBox.showURL(url,'',
	{   
	    width: myWidth ,
	    ignore_target: 'true'
	});

	return false;
}

function updateDownload(download_id, cstID, prdID, mboxID, link, cstType, fileType) {
	var mboxtype="";
	if (cstType != "subscribers" && cstType != "suppliers") {
		if (link != "" && link != "0") {
			window.open(link);
			return false;
		}
	}
	
	if (link == "" || link == "0") {
		//re-create mbox link for client
		if(fileType=="playback")
		{
			mboxtype=3;
		}
		else
		{
			mboxtype=4;
		}
		var url = _base+"/kara_ajax.php?action=get_mbox&prdID="+prdID+"&mboxID="+mboxID+"&mboxType="+mboxtype;
		var new_link = LoadHTML(url);
		if(new_link != null)
		{
			return updateDownload(download_id, cstID, prdID, mboxID, new_link, cstType, fileType);
		}
	} else {
		var url = _base+"/kara_ajax.php?action=updateDownload&download_id="+download_id+"&prdID="+prdID+"&fileType="+fileType+"&cstID="+cstID+"&link="+link+"&cstType="+cstType;
		var xml = LoadHTML(url);
		if(xml != null)
		{
			var url = _base+"/kara_ajax.php?action=updateLog&log_string="+xml+"&log_function=download_link&log_direction=Send";
			var xml = LoadHTML(url);
			window.open(link);
			location.reload();
		}
		return false;
	}
}

function checkLogin(cForm)
{
	if (cForm.userName.value == "" || cForm.password.value == "")
	{
		alert(_login_userandpass);
		if(cForm.userName.value == "")
			cForm.userName.focus();
		else if(cForm.password.value == "")
			cForm.password.focus();
	}
	else
	{
		// ajax check login
		var url = _base+"/tyco_login.ajax.php?logMember=true&userName="+cForm.userName.value+"&password="+cForm.password.value+"&cstType="+cForm.cstType.value;
		var xml = LoadXML(url);
		if(xml != null)
		{
			if (xml.getElementsByTagName('login')[0].firstChild.data == "logged"){
				location.reload();
			}
			else
			{
				var message = xml.getElementsByTagName('rsp')[0].firstChild.data;
				alert (message);
				cForm.userName.focus();
			}
		}
	}
	return false;
}

function send_pwr(cForm, cstType)
{
	
	if (cForm.reminderEmail.value == "" || !checkEmail(cForm.reminderEmail.value))
	{
		alert(_contact_emailInvalid);
		cForm.reminderEmail.focus();
	}
	else
	{
		// ajax check login
		var url = _base+"/kara_ajax.php?action=pwr&reminderEmail="+cForm.reminderEmail.value+"&cstType="+cstType;
		var xml = LoadHTML(url);
		if(xml != null)
		{
			alert (xml);
			cForm.reminderEmail.value = "";
		}
	}
	return false;
}

function get_pwr(d, t) {
	
	d = document.getElementById(d);
	var url = _base+"/kara_ajax.php?action=get_pwr&cstType="+t;
	var xml = LoadHTML(url);
	if(xml != null)
	{
		d.innerHTML = xml;
		return false;
	}
	return false;	
}

function updateMember(f)
{
	// disable submit button and change its class
	submitButton = f.submitForm;
	submitButton.disabled = true;

	ReqFields = new Array("firstName","lastName","email","phone");
	for (i=0;i<ReqFields.length; i++)
	{
		fieldName = ReqFields[i];
		if (trim(f[fieldName].value) == "")
		{
			cMessage = eval("_"+fieldName);
			alert(cMessage);
			f[fieldName].focus();
			submitButton.disabled = false;
			return false;
		}

		if (fieldName == "email" && !checkEmail(f[fieldName].value))
		{
			alert(_emailInvalid);
			f[fieldName].focus();
			submitButton.disabled = false;
			return false;
		}

		if (fieldName == "_phone" && !checkPhone(f[fieldName].value))
		{
			alert(_phoneInvalid);
			f[fieldName].focus();
			submitButton.disabled = false;
			return false;
		}

	}

	if (confirm(_update_confirm))
	{
		advAJAX.submit(f, {
		    onSuccess : function(obj) {
		    		if (obj.responseText == "success")
		    		{
		    			alert (_update_success);
		    			submitButton.disabled = false;
		    		}
		    		else
		    		{
		    			alert (_update_fail);
		    			f.reset();
		    			submitButton.disabled = false;
		    		}
		    }
		});
		return false;
	}

	submitButton.disabled = false;
	return false;
}

function updatePassword(f)
{
	// disable submit button and change its class
	submitButton = f.submitForm;
	submitButton.disabled = true;

	if (f.userName.value == '')
	{
		f.userName.value = f.userName_orig.value;
	}

	if (f.current_password.value != "" || f.new_password.value != "")
	{
		ReqFields = new Array("current_password","new_password","verify_password");
		for (i=0;i<ReqFields.length; i++)
		{
			fieldName = ReqFields[i];
			if (trim(f[fieldName].value) == "")
			{
				cMessage = eval("_"+fieldName);
				alert(cMessage);
				f[fieldName].focus();
				submitButton.disabled = false;
				return false;
			}
		}
		if (f.new_password.value != f.verify_password.value) {
			alert(_match_password);
			f.verify_password.focus();
			submitButton.disabled = false;
			return false;
		}
	}

	if (confirm(_update_confirm))
	{
		advAJAX.submit(f, {
		    onSuccess : function(obj) {
		    		if (obj.responseText == "success")
		    		{
		    			alert (_update_success);
		    			new_user = f.userName.value;
		    			f.reset();
		    			f.userName.value = new_user;
		    			submitButton.disabled = false;
		    		}
		    		else
		    		{
		    			alert (obj.responseText);
		    			f.reset();
		    			submitButton.disabled = false;
		    		}
		    }
		});
		return false;
	}

	submitButton.disabled = false;
	return false;
}

function downloadLicense_login(cForm) {
	// try to login customer and download file using license if all valid
	if (cForm.userName.value == "" || cForm.password.value == "")
	{
		alert(_login_userandpass);
		if(cForm.userName.value == "")
			cForm.userName.focus();
		else if(cForm.password.value == "")
			cForm.password.focus();
		return false;
	}
	
	// ajax check login
	var url = _base+"/tyco_login.ajax.php?logMember=true&userName="+cForm.userName.value+"&password="+cForm.password.value+"&cstType="+cForm.cstType.value;
	var xml = LoadXML(url);
	if(xml != null)
	{
		if (xml.getElementsByTagName('login')[0].firstChild.data == "logged"){
			cstID = xml.getElementsByTagName('cstID')[0].firstChild.data;
			prdID = cForm.prdID.value;
			type = cForm.type.value;
			downloadLicense(cstID, prdID, type);
		}
		else
		{
			var message = xml.getElementsByTagName('rsp')[0].firstChild.data;
			alert (message);
			cForm.userName.focus();
		}
	}

	return false;
	
}

function downloadLicense(cstID,  prdID, type) {

	// check if file was not already loaded previously by this customer
	var url = _base+"/kara_ajax.php?action=checkDownload&prdID="+prdID+"&cstID="+cstID+"&type="+type;
	var xml = LoadHTML(url);
	/*if (xml != null && xml != "" && !confirm(_download_exists)) {
		return false;
	}*/
	if (xml != null && xml != "") {
		alert (_download_exists);
		return false;
	}
	
	//CHECK DEAL TYPE PLAYBACK OR CLIP OLD SUBSCRIBERS ONLY CLIPS WILL PASS
	var url = _base+"/kara_ajax.php?action=checkDealType&type="+type+"&cstID="+cstID;
	var xml = LoadHTML(url);
	
	if (xml != null && xml != "") {
		
		if(type=="playback")
		{
			alert (_deal_not_exists_play);
		}
		else
		{
			alert (_deal_not_exists_clip);
		}
		
		
		return false;
	}
	
	var url = _base+"/kara_ajax.php?action=downloadLicense&prdID="+prdID+"&cstID="+cstID+"&type="+type;
	var xml = LoadHTML(url);
	if(xml != null && xml != "")
	{
		location.replace(xml);
		return false;
	}
	else
	{
		alert(_license_invalid);
		return false;
	}
	
}
function getMnfSongs(mnfID,artistID, f, cValue){
	songsSelect = f.mnf_art_songs;
	
	var mnf_sel = $("select[name=mnf_cst_type]").val();
	if( mnf_sel > 0  )
		mnfID = mnf_sel;
	
	var url = _base+"/kara_ajax.php?action=manufactures&mnfID="+mnfID+"&artistID="+artistID;
	var xml = LoadXML(url);
 	if(xml != null) {
 		  var fields = xml.getElementsByTagName('field');
 		  var values = xml.getElementsByTagName('value');
		  for(var j = songsSelect.options.length; j >= 0; j --) {
		  	songsSelect.options[j] = null;
		  }
		  var allSongsOpt = new Option(_allSongs, "all");
		  songsSelect.options[0] = allSongsOpt;
		  for(var k = 0; k < fields.length; k++) {
			   var data = fields[k].firstChild.data;
			   var id = values[k].firstChild.data;
			   var opt = new Option(data, id);
			   songsSelect.options[k+1] = opt;
			   if (cValue != null && cValue != "" && cValue == id) songsSelect.selectedIndex = k+1;
 		}
	}
}

function get_mnf_artists(provider_id)
{
	if( provider_id == "" ) provider_id = "all";
	var all_songs_option = "<option value='all'>"+_allSongs+"</option>";
	$.ajax({
	type: "POST",
	url: _base +"/kara_ajax.php?action=get_mnf_artists&provider_id="+provider_id,
	data: "provider_id="+provider_id,
	success: function(data){
			$("select[name=mnf_artist]").html(data);
			$("select[name=mnf_art_songs]").html(all_songs_option);
		} 
	});
	return false;
}

function checkpass(curForm)
{
	if(curForm.reminderEmail.value=="")
	{
		alert(_alert_email);
		curForm.reminderEmail.focus();
		return false;
	}
	if (!checkEmail(curForm.reminderEmail.value))
	{
		alert(_tpl_emailNotValid);
		curForm.reminderEmail.focus();

		return false;
	}
}

function refreshResults(link, ql) {
	if (ql != '' && ql > 0) {
		window.location.href=link + "?ql="+ql;
	}
	else
	{
		window.location.href=link;
	}
		
}

function checkCartForm(f,incship)
{
	// disable submit button and change its class
	submitButton = f.submitForm;
	submitButton.disabled = true;
	if(incship) 
		ReqFields = new Array("firstName","lastName","email","phone","street","city");
	else
		ReqFields = new Array("firstName","lastName","email","phone");
		
	for (i=0;i<ReqFields.length; i++)
	{
		fieldName = ReqFields[i];
		if (trim(f[fieldName].value) == "")
		{
			cMessage = eval("_"+fieldName);
			alert(cMessage);
			f[fieldName].focus();
			submitButton.disabled = false;
			return false;
		}

		if (fieldName == "email" && !checkEmail(f[fieldName].value))
		{
			alert(_emailInvalid);
			f[fieldName].focus();
			submitButton.disabled = false;
			return false;
		}

		if (fieldName == "_phone" && !checkPhone(f[fieldName].value))
		{
			alert(_phoneInvalid);
			f[fieldName].focus();
			submitButton.disabled = false;
			return false;
		}

	}
	
	if(f.CC_month.value<10)
	{
		f.tran_month.value="0"+f.CC_month.value;
	}
	else
	{
		f.tran_month.value=f.CC_month.value;
	}
	f.tran_year.value=f.CC_year.value.substring(2);
	f.expdate.value=f.tran_month.value+f.tran_year.value;
	
	if(!checkCartCreditCard()) //netcommerance in creditCardFix.js script
	{
		submitButton.disabled = false;
		return false;
	}
	
	
	
	if (f.CC_cvc.value=="")
	{
		alert(_CC_cvc_empty);
		f.CC_cvc.focus();
		submitButton.disabled = false;
		return false;
	}
	
	if (f.myid.value=="")
	{
		alert(_CC_myid);
		submitButton.disabled = false;
		f.myid.focus();
		return false;
	}
	
	
	if (!f.terms.checked)
	{
		alert(_alert_terms);
		submitButton.disabled = false;
		return false;
	}
	
	
	//CHECK SHIPMENT
	var shipment=document.getElementById("shipMetID");
	if(shipment.value)
	{
		f.shipMethod.value=shipment.value;
	}
	return true;
	
}

function checkSubCartForm(f,incship)
{
	var illegalchars =/[\W_]/;
	// disable submit button and change its class
	submitButton = f.submitForm;
	submitButton.disabled = true;
	
	var chosen = ""
	len = f.subchk.length
	for (i = 0; i <len; i++) 
	{
		if (f.subchk[i].checked) 
		{
			chosen = f.subchk[i].value
		}
	}
	
	if(chosen=='returneduser')
	{
		if (f.userNameRet.value == "" || f.passwordRet.value == "")
		{
			alert(_login_userandpasscart);
			if(f.userNameRet.value == "")
				f.userNameRet.focus();
			else if(f.passwordRet.value == "")
				f.passwordRet.focus();
				
				submitButton.disabled = false;
				return false
		}
		else
		{
			var userurl = _base+"/kara_ajax.php?action=check_login&userName="+f.userNameRet.value+"&password="+f.passwordRet.value;
			var userxml = LoadXML(userurl);
			if(userxml != null)
			{
				if (userxml.getElementsByTagName('user_var')[0] && userxml.getElementsByTagName('user_var')[0].firstChild && userxml.getElementsByTagName('user_var')[0].firstChild.data)
				{
					if(userxml.getElementsByTagName('user_var')[0].firstChild.data==0)
					{
						alert (userPassMsg);
						f.userNameRet.focus();
						submitButton.disabled = false;
						return false;
					}
				}
			}
			//cHECK HAS NO ACTIVE SUBSCIPTION
			var userurl = _base+"/kara_ajax.php?action=check_active_subscribe&userName="+f.userNameRet.value+"&password="+f.passwordRet.value;
			var userxml = LoadXML(userurl);
			if(userxml != null)
			{
				if (userxml.getElementsByTagName('user_var')[0] && userxml.getElementsByTagName('user_var')[0].firstChild && userxml.getElementsByTagName('user_var')[0].firstChild.data)
				{
					if(userxml.getElementsByTagName('user_var')[0].firstChild.data==1)
					{
						alert (_userhassubscribeMsg);
						submitButton.disabled = false;
						return false;
					}
				}
			}
		}
	}
	else
	{
		if(incship) 
			ReqFields = new Array("firstName","lastName","email","phone","userName","password","check_password","street","city");
		else
			ReqFields = new Array("firstName","lastName","email","phone","userName","password","check_password");
				
			for (i=0;i<ReqFields.length; i++)
			{
				fieldName = ReqFields[i];
				if (trim(f[fieldName].value) == "")
				{
					cMessage = eval("_"+fieldName);
					alert(cMessage);
					f[fieldName].focus();
					submitButton.disabled = false;
					return false;
				}
		
				if (fieldName == "email" && !checkEmail(f[fieldName].value))
				{
					alert(_emailInvalid);
					f[fieldName].focus();
					submitButton.disabled = false;
					return false;
				}
				
				if (fieldName == "email")
				{
					var userurl = _base+"/kara_ajax.php?action=get_email&email="+f.email.value;
					var userxml = LoadXML(userurl);
					if(userxml != null)
					{
						if (userxml.getElementsByTagName('user_var')[0] && userxml.getElementsByTagName('user_var')[0].firstChild && userxml.getElementsByTagName('user_var')[0].firstChild.data)
						{
				
							email = userxml.getElementsByTagName('user_var')[0].firstChild.data;
						}
						else
						{
							email =1;
						}
					}
					if (email==1)
					{
						alert(_alert_exsist_email);
						f[fieldName].focus();
						submitButton.disabled = false;
						return false;
					}
				}
		
				if (fieldName == "phone" && !checkPhone(f[fieldName].value))
				{
					alert(_phoneInvalid);
					f[fieldName].focus();
					submitButton.disabled = false;
					return false;
				}
				if (fieldName == "userName" && illegalchars.test(f[fieldName].value))
				{
					alert(_alert_username_invalid);
					f[fieldName].focus();
					submitButton.disabled = false;
					return false;
				}
				if (fieldName == "userName")
				{
					var userurl = _base+"/kara_ajax.php?action=get_username&username="+f.userName.value;
					var userxml = LoadXML(userurl);
					if(userxml != null)
					{
						if (userxml.getElementsByTagName('user_var')[0] && userxml.getElementsByTagName('user_var')[0].firstChild && userxml.getElementsByTagName('user_var')[0].firstChild.data)
						{
				
							username = userxml.getElementsByTagName('user_var')[0].firstChild.data;
						}
						else
						{
							username =1;
						}
					}
					if (username==1)
					{
						alert(_alert_exsist_username);
						f[fieldName].focus();
						submitButton.disabled = false;
						return false;
					}
				}
				
				if (fieldName == "password" && illegalchars.test(f[fieldName].value))
				{
					alert(_alert_password_invalid);
					f[fieldName].focus();
					submitButton.disabled = false;
					return false;
				}
		
			}
			
				if (f['password'].value!=f['check_password'].value)
				{
					alert(_alert_pasnomatch);
					f['password'].focus();
					submitButton.disabled = false;
					return false;
				}
			
			
	}
	
	if(f.CC_month.value<10)
		{
			f.tran_month.value="0"+f.CC_month.value;
		}
		else
		{
			f.tran_month.value=f.CC_month.value;
		}
		f.tran_year.value=f.CC_year.value.substring(2);
		f.expdate.value=f.tran_month.value+f.tran_year.value;
		
		if(!checkCartCreditCard())//netcommerance in creditCardFix.js script
		{
			submitButton.disabled = false;
			return false;
		}
		
		
		
		if (f.CC_cvc.value=="")
		{
			alert(_CC_cvc_empty);
			f.CC_cvc.focus();
			submitButton.disabled = false;
			return false;
		}
		
		if (f.myid.value=="")
		{
			alert(_CC_myid);
			f.myid.focus();
			submitButton.disabled = false;
			return false;
		}
	
	
	if(chosen!='returneduser')
	{	
		if (!f.terms.checked)
		{
			alert(_alert_terms);
			submitButton.disabled = false;
			return false;
		}
	}
	
	return true;
	
}

function setNewSubscriber(){
// SWITCH SELECTED ELEMENT DISPLAY: NONE/INLINE
		document.getElementById("returnSubscriber").style.display="block";
		document.getElementById("LoginOnly").style.display="none";
		document.getElementById("terms").style.display="block";
}

function setReturnSubscriber(){
// SWITCH SELECTED ELEMENT DISPLAY: NONE/INLINE
		document.getElementById("returnSubscriber").style.display="none";
		document.getElementById("LoginOnly").style.display="block";
		document.getElementById("terms").style.display="none";
}

function checkSupDetails(f)
{
	// disable submit button and change its class
	submitButton = f.submitForm;
	submitButton.disabled = true;

	ReqFields = new Array("fullName");
	for (i=0;i<ReqFields.length; i++)
	{
		fieldName = ReqFields[i];
		if (trim(f[fieldName].value) == "")
		{
			cMessage = eval("_"+fieldName);
			alert(cMessage);
			f[fieldName].focus();
			submitButton.disabled = false;
			return false;
		}

	}
	if ($("ul.areas input:checked").length==0) {
    		alert(_placeChoose);
    		submitButton.disabled = false;
    		return false;
	}
	
	if ($("div.new_cart_long input:checked").length==0 && f.visableSup.value=='Y') {
    		alert(_suptermschk);
    		submitButton.disabled = false;
    		return false;
	}

	if (confirm(_update_confirm))
	{
		advAJAX.submit(f, {
		    onSuccess : function(obj) {
    			alert (_update_success);
    			submitButton.disabled = false;
    			window.location.reload();
		    }
		});
		return false;
		//return true;
	}

	submitButton.disabled = false;
	return false;
}

function check_active(sel)
{
	if(sel.value=='N')
		$('#termst').attr('checked', false)
}

function checkClubDetails(f)
{
	// disable submit button and change its class
	submitButton = f.submitForm;
	submitButton.disabled = true;

	ReqFields = new Array("fullName");
	for (i=0;i<ReqFields.length; i++)
	{
		fieldName = ReqFields[i];
		if (trim(f[fieldName].value) == "")
		{
			cMessage = eval("_"+fieldName);
			alert(cMessage);
			f[fieldName].focus();
			submitButton.disabled = false;
			return false;
		}

	}
	if ($("input:checked").length==0) {
    		alert(_daysChoose);
    		submitButton.disabled = false;
    		return false;
	}

	if (confirm(_update_confirm))
	{
		return true;
	}

	submitButton.disabled = false;
	return false;
}

function checkPic(f)
{
	// disable submit button and change its class
	submitButton = f.submitForm;
	submitButton.disabled = true;
	ReqFields = new Array("picture");
	for (i=0;i<ReqFields.length; i++)
	{
		fieldName = ReqFields[i];
		if (trim(f[fieldName].value) == "")
		{
			cMessage = eval("_"+fieldName);
			$("#picmsg").text(cMessage);
			f[fieldName].focus();
			submitButton.disabled = false;
			return false;
		}
		else
		{
			$("#picmsg").text("");
		}

	}
	
	var ext = $('#picture').val().split('.').pop().toLowerCase(); 
	var allow = new Array('gif','png','jpg','jpeg'); 
	if(jQuery.inArray(ext, allow) == -1) { 
	    $("#picmsg").text(_PicNotAllowed);
	}
	else
	{
		$("#picmsg").text("");
	}
	return true;	
}

function removePic(picname)
{
	if (confirm(_delete_pic))
	{
		var url = _base+"/kara_ajax.php?action=delete_pic&pic="+picname;
		var xml = LoadHTML(url);
		if(xml != null)
		{
			$("#JQReplace").html(xml);
			return false;
		}
	}
}

function removesup(id)
{
	if (confirm(_delete_sup))
	{
		var url = _base+"/kara_ajax.php?action=deleteLinkedSup&id="+id;
		var xml = LoadHTML(url);
		if(xml != null)
		{
			$("#JQsupWrap").html(xml);
			var supsnumber=document.getElementById("numofsup");
			supsnumber.value=parseInt(supsnumber.value)-1;
			window.location.reload();
			return false;
		}
	}
}

function updateSup(curForm)
{
	if(curForm.linked_cst.value!='none')
	{
		var url = _base+"/kara_ajax.php?action=updateLinkedSup&linked_cst="+curForm.linked_cst.value+"&numofsup="+curForm.numofsup.value;
		var xml = LoadHTML(url);
		if(xml != null)
		{
			$("#JQsupWrap").html(xml);
			curForm.numofsup.value=parseInt(curForm.numofsup.value)+1;
			/*if(parseInt(curForm.numofsup.value)>4)
			{
				$('document').ready(function(){ 
					    $("#supgal").jCarouselLite({
					        btnPrev: "#supgal_left",
					        btnNext: "#supgal_right" ,
					        easing: "easeout",
						   speed: 1000 ,
						   visible :4 ,
						    mouseWheel: true
					    });
					})
			}*/
			window.location.reload();
			
			
			return false;
		}
	}
	else
	{
		alert(_chose_sup);
		return false;
	}
	
}

function checkPacall(f)
{
	submitButton = document.getElementById("submitForm");
	submitButton.disabled = true;
	
	ReqFields = new Array("firstName","lastName","email");
	for (i=0;i<ReqFields.length; i++)
	{
		fieldName = ReqFields[i];
		if (trim(f[fieldName].value) == "")
		{
			cMessage = eval("_"+fieldName);
			alert(cMessage);
			f[fieldName].focus();
			submitButton.disabled = false;
			return false;
		}

		if (fieldName == "email" && !checkEmail(f[fieldName].value))
		{
			alert(_emailInvalid);
			f[fieldName].focus();
			submitButton.disabled = false;
			return false;
		}

	}
	
	if (!f.terms.checked)
	{
		alert(_alert_terms);
		submitButton.disabled = false;
		return false;
	}
	return true;
}

var smsflag=false;

function submitSupContact(f)
{
	// disable submit button and change its class
	submitButton = document.getElementById("submitForm");
	submitButton.disabled = true;
	var flag=0;

	ReqFields = new Array("contact_fName","contact_phone","contact_email","fromDate");
	for (i=0;i<ReqFields.length; i++)
	{
		fieldName = ReqFields[i];
		if (trim(f[fieldName].value) == "")
		{
			if(fieldName == "contact_phone" )
				cMessage = _contact_mobile;
			else
				cMessage = eval("_"+fieldName);	
			alert(cMessage);
			f[fieldName].focus();
			submitButton.disabled = false;
			return false;
		}

		if (fieldName == "contact_email" && !checkEmail(f[fieldName].value))
		{
			alert(_contact_emailInvalid);
			f[fieldName].focus();
			submitButton.disabled = false;
			return false;
		}

		if (fieldName == "contact_phone" && !checkmobilePhone(f[fieldName].value))
		{
			alert(_contact_mobileInvalid);
			f[fieldName].focus();
			submitButton.disabled = false;
			return false;
		}
	}
	
	if(f.event_place.value=="ALL")
	{
		alert(_choose_place);
		submitButton.disabled = false;
		return false;
	}
	else
	{
		$("#contact_operator").hide();
		$("#operator_thanks").hide();
		$("#operator_sms").show();
     		submitButton.disabled = false;
     		
     		if(!smsflag)
     		{
     		//SENDSMS
     		   var url = _base+"/kara_ajax.php?action=sendSms&phone="+f.contact_phone.value;
			var xml = LoadXML(url);
			if(xml != null)
			{
				if (xml.getElementsByTagName('var')[0] && xml.getElementsByTagName('var')[0].firstChild && xml.getElementsByTagName('var')[0].firstChild.data)
				{
					smsStatus = xml.getElementsByTagName('var')[0].firstChild.data;
					if(smsStatus!='sent')
					{
						alert(_sms_error);
						return false;
					}
				}
				else
				{
					alert(_sms_error);
						return false;
				}
			}
			smsflag=true;
     		}
	}
	
     
     if(f.smsCode.value=="")
     {
     		alert(_choose_smscode);
     		f.smsCode.focus();
     		submitButton.disabled = false;
     		return false;
     }
     
     var url = _base+"/kara_ajax.php?action=get_session&session_name=SmsSeed";
	var xml = LoadXML(url);
	if(xml != null)
	{
		if (xml.getElementsByTagName('session_var')[0] && xml.getElementsByTagName('session_var')[0].firstChild && xml.getElementsByTagName('session_var')[0].firstChild.data)
		{
			security_code = xml.getElementsByTagName('session_var')[0].firstChild.data;
		}
		else
		{
			security_code = "";
		}
	}
	if (trim(f.smsCode.value) != security_code)
	{
		alert(_sec_code);
		f.smsCode.focus();
		submitButton.disabled = false;
		return false;
	}
	else
	{
		$("#operator_sms").hide();
     		$("#contact_operator").show();
	}
	
	//if (confirm(_contact_confirm))
	//{
		advAJAX.submit(f, {
		    onSuccess : function(obj) {
		    		if (obj.responseText != "")
		    		{
		    			/*alert (_contact_success);
		    			f.reset();
		    			submitButton.disabled = false;*/
		    			$("#contact_operator").hide();
		    			$("#operator_thanks").show();
		    		}
		    		else
		    		{
		    			alert (_contact_fail);
		    			submitButton.disabled = false;
		    		}
		    }
		});
		return false;
		//return true;
	//}

	submitButton.disabled = false;
	return false;
}

function setAreas(chkobj,strid)
{
	var mainul=document.getElementById(strid)
	if(chkobj.checked)
	{
		$(mainul).find("input").each(function() {
			$(this).attr('checked',true);
		});
	}
	else
	{
		$(mainul).find("input").each(function() {
			$(this).attr('checked',false);
		});
	}
}

function check_checked(f)
{
	if($("input:checked").length==0)
	{
		alert(_chose_atleastone);
		return false;
	}
	else
	{
		if(confirm(_remove_lines))
		{
			return true;
		}
	}
	return false;
}

function setAllAreas(cur)
{
	if(cur.checked)
	{
		$("input[type=checkbox]").each(function() 
			{
				$(this).attr('checked',true);
			}
		);
		return true;
	}
	else
	{
		$("input:checked").attr('checked',false);
		return true;
	}
}

function GetCreditCardTypeByNumber(ccnumber) 
{
	var cc = (ccnumber + '').replace(/\s/g, ''); //remove space
	
	if ((/^(34|37)/).test(cc) && cc.length == 15) 
	{
		return 'AMEX'; //AMEX begins with 34 or 37, and length is 15.
	}
	else if ((/^(51|52|53|54|55)/).test(cc) && cc.length == 16) 
	{
		return 'MasterCard'; //MasterCard beigins with 51-55, and length is 16.
	}
	else if ((/^(4)/).test(cc) && (cc.length == 13 || cc.length == 16)) 
	{
		return 'Visa'; //VISA begins with 4, and length is 13 or 16.
	}
	else if ((/^(300|301|302|303|304|305|36|38)/).test(cc) && cc.length == 14) 
	{
		return 'DinersClub'; //Diners Club begins with 300-305 or 36 or 38, and length is 14.
	}
	else if ((/^(2014|2149)/).test(cc) && cc.length == 15) 
	{
		return 'enRoute'; //enRoute begins with 2014 or 2149, and length is 15.
	}
	else if ((/^(6011)/).test(cc) && cc.length == 16) 
	{
		return 'Discover'; //Discover begins with 6011, and length is 16.
	}
	else if ((/^(3)/).test(cc) && cc.length == 16) 
	{
		return 'JCB';  //JCB begins with 3, and length is 16.
	}
	else if ((/^(2131|1800)/).test(cc) && cc.length == 15) 
	{
		return 'JCB';  //JCB begins with 2131 or 1800, and length is 15.
	}
	
	if ( cc.length == 8 || cc.length == 9 ) 
	{
		return 'Isracard';
	}
	return '?'; //unknow type
}
 
function IsValidCC(str) 
{ 
	//A boolean version
    if (GetCreditCardTypeByNumber(str) == '?') return false;
    
    return true;
}

function check_cc_type()
{
	var cc_num = $("input[name=CC_num]").val();
	var cc_type = GetCreditCardTypeByNumber(cc_num);
	
	if( cc_type == "?" )
		cc_type = "Visa";
	$("input[name=CC_type]").val(cc_type);
}

function checkForm(f)
{
	// disable submit button and change its class
	submitButton = document.getElementById("submitForm");
	submitButton.disabled = true;
	var flag=0;

	ReqFields = new Array("contact_phone");
	for (i=0;i<ReqFields.length; i++)
	{
		fieldName = ReqFields[i];
		if (trim(f[fieldName].value) == "")
		{
			if(fieldName == "contact_phone" )
				cMessage = _contact_mobile;
			else
				cMessage = eval("_"+fieldName);	
			alert(cMessage);
			f[fieldName].focus();
			submitButton.disabled = false;
			return false;
		}
		

		/*if (fieldName == "contact_phone" && !checkPhone(f[fieldName].value))
		{
			alert(_contact_mobileInvalid);
			f[fieldName].focus();
			submitButton.disabled = false;
			return false;
		}*/
	}
	if (!f.termsapp.checked)
	{
		alert(_alert_terms);
		submitButton.disabled = false;
		return false;
	}
	return true;
}
