function doAjaxPost(myCartID,myPrice){
	//index.php?mode=product&action=add2cart&prod_id=
	jQuery.blockUI({ message:  '<p class="waitmsg">Please wait...</p>', centerY: 0, overlayCSS: { backgroundColor: '#000' },css: { top: '10px', left: '', right: '10px', border: '1px solid #a00'} }); 
	jQuery.ajax({
		url : "ajaxpost.php",
		cache: false,
		data: "tracker=cart&prod_id="+myCartID+"&price="+myPrice,
		success : function (data) {
			if(data.length>=5){
				alert("Error : "+data);
			} else {
				jQuery("#p_count").html(data+' items');
			}
			jQuery.unblockUI();
		}
	});
	jQuery("#p_count").ajaxSend(function(r,s){
		jQuery.blockUI({ message:  '<p class="waitmsg">Please wait...</p>', centerY: 0, overlayCSS: { backgroundColor: '#000' },css: { top: '10px', left: '', right: '10px', border: '1px solid #a00'} }); 
	});   

	jQuery("#p_count").ajaxStop(function(r,s){   
		jQuery.unblockUI();
	});
}
function doCheckOut(){
	self.location='index.php?mode=prod&action=order';
}
function applyCoupon(theval){
	document.cform.selid.value=theval; 
	document.cform.pageaction.value='CouponApply'; 
	document.cform.submit();
}
function RemoveDiscount(theval){
	document.cform.selid.value=theval; 
	document.cform.pageaction.value='CouponRemove'; 
	document.cform.submit();
}
function doupdateCart(){
	document.cform.pageaction.value='update'; 
	document.cform.submit();
}
function doDeleteCart(seeID){
	//send messag ethen delete the item
	document.cform.pageaction.value='delete';
	document.cform.singleIDdelete.value=seeID; 
	document.cform.submit();
}
function doClearCart(){
	//send message the clear the card
	document.cform.pageaction.value='clear';
	document.cform.submit();
}
function restclass(myID){
	if(document.getElementById(myID).value!=''){
		document.getElementById(myID).className = "input-text";
	} else {
		document.getElementById(myID).className = "input-text error";
	}
}
function previewVideo(p_id,imgName,rowid){
	var repUrl = "upcpadm/image/prod_item/"+p_id+"/"+imgName;
	jQuery("#videoPreview").html(getPreviewText(repUrl,120,125));
	jQuery("#videoName").html(imgName);
}
function checkQty(oldVal,newVal){
	oldVal = parseFloat(oldVal);
	newVal = parseFloat(newVal);
	if (String(newVal).indexOf(".") > 0) {
		return false;
	}
	if(newVal>oldVal){
		jQuery("#Qty").val('1');
		return false;
	}
}
function doCalculate(rid){
	var s_newlprice = 0;	var s_saleprice = 0;	var s_pertage = 0;	var s_saveAmount = 0;
	var r_newlprice = 0;	var r_saleprice = 0;	var r_pertage = 0;	var r_saveAmount = 0;
	var selectdata = "";	var radiodata = "";	var checkdata = "";
	var orgListPrice = jQuery("#listprice").val();
	var orgsaleprice = jQuery("#saleprice").val();
	var orgpertange = jQuery("#persentage").val();
	//loop the data
	//first check for select box
	var vtypes = document.getElementById("vtypes").value;
	var isRadio = new Array();	var isSelect = new Array();	var isCheck = new Array();
	vtypes = vtypes.split("|");
	for (x in vtypes){
		vtypes[x] = vtypes[x].split(",");
		if(vtypes[x][0]=="R"){
			isRadio[0] = true;
			isRadio[1] = vtypes[x][1];
			//name=\"opt_radio[$id][$v[id]]\"
			var incount = document.getElementsByName("opt_radio["+rid+"]["+isRadio[1]+"]").length;
			for (i=0;i<incount;i++){
				if(document.getElementById("radio_"+rid+"_"+isRadio[1]+"_"+i).checked==true){
					radiodata = document.getElementById("radio_"+rid+"_"+isRadio[1]+"_"+i).value;
					radiodata = doSelectAdd(radiodata);
					radiodata = radiodata.split("|");
					if(radiodata[3]=='+'){			//add
						s_newlprice = parseFloat(orgListPrice)+parseFloat(radiodata[0]);
						s_saleprice = parseFloat(orgsaleprice)+parseFloat(radiodata[0]);
					} else {			//min
						s_newlprice = parseFloat(orgListPrice)-parseFloat(radiodata[0]);
						s_saleprice = parseFloat(orgsaleprice)-parseFloat(radiodata[0]);
					}
					s_saveAmount = (s_newlprice-s_saleprice);
					s_pertage = parseFloat((parseFloat(s_saveAmount)/s_newlprice)*100);
				}
			}
		}
		if(vtypes[x][0]=="S"){
			isSelect[0] = true;
			isSelect[1] = vtypes[x][1];
			selectdata = (document.getElementById("opt_select_"+rid+"_"+isSelect[1]).value);
			selectdata = doSelectAdd(selectdata);
			selectdata = selectdata.split("|");
			if(selectdata[3]=='+'){			//add
				s_newlprice = parseFloat(orgListPrice)+parseFloat(selectdata[0]);
				s_saleprice = parseFloat(orgsaleprice)+parseFloat(selectdata[0]);
			} else {			//min
				s_newlprice = parseFloat(orgListPrice)-parseFloat(selectdata[0]);
				s_saleprice = parseFloat(orgsaleprice)-parseFloat(selectdata[0]);
			}
			s_saveAmount = (s_newlprice-s_saleprice);
			s_pertage = parseFloat((parseFloat(s_saveAmount)/s_newlprice)*100);
		}
		if(vtypes[x][0]=="C"){
			isCheck[0] = true;
			isCheck[1] = vtypes[x][1];
			if(document.getElementById("opt_check_"+rid+"_"+isCheck[1]).checked == true){
				checkdata = (document.getElementById("opt_check_"+rid+"_"+isCheck[1]).value);	
			} else {
				checkdata = isCheck[1];
			}
			checkdata = doSelectAdd(checkdata);
			checkdata = checkdata.split("|");
			if(checkdata[3]=='+'){			//add
				s_newlprice = parseFloat(orgListPrice)+parseFloat(checkdata[0]);
				s_saleprice = parseFloat(orgsaleprice)+parseFloat(checkdata[0]);
			} else {			//min
				s_newlprice = parseFloat(orgListPrice)-parseFloat(checkdata[0]);
				s_saleprice = parseFloat(orgsaleprice)-parseFloat(checkdata[0]);
			}
			s_saveAmount = (s_newlprice-s_saleprice);
			s_pertage = parseFloat((parseFloat(s_saveAmount)/s_newlprice)*100);
		}
		orgListPrice = s_newlprice;
		orgsaleprice = s_saleprice;
		orgpertange = s_pertage;
	}
	jQuery("#jslprice").html(orgListPrice.toFixed(2));
	jQuery("#jspprice").html(orgsaleprice.toFixed(2));
	jQuery("#jspertage").html("("+orgpertange.toFixed(0)+"%)");
	jQuery("#jspertage_1").html(orgpertange.toFixed(0)+"%");
	jQuery("#jssaveamt").html(s_saveAmount.toFixed(2));
}
function doSelectAdd(myIDValue){
	//81 + 1 A
	var newlprice = 0;	var saleprice = 0;	var pertage = 0;	var saveAmount = 0;
	var newlprice_0 = 0; var saleprice_0 =0;
	var arrnewcal = myIDValue.split("|");
	var oldListPrice = jQuery("#listprice").val();
	var oldsaleprice = jQuery("#saleprice").val();
	var oldpertange = jQuery("#persentage").val();
if(oldListPrice==0)	{
	if(arrnewcal[1]=="+"){ //Adding
		if(arrnewcal[3]=="A"){ //Adding
			saleprice = parseFloat(oldsaleprice)+parseFloat(arrnewcal[2]);
			newlprice_0 = parseFloat(arrnewcal[2]);
			pertage = 0;
		} else { //Perstage
			new_sper = parseFloat(oldsaleprice) * parseFloat(arrnewcal[2])/100;
			saleprice = parseFloat(oldsaleprice)+parseFloat(new_sper);
			newlprice_0 = parseFloat(new_sper);
			pertage = 0;
		}
	} else if(arrnewcal[1]=="-"){
		if(arrnewcal[3]=="A"){ //Adding
			saleprice = parseFloat(oldsaleprice)-parseFloat(arrnewcal[2]);
			newlprice_0 = parseFloat(arrnewcal[2]);
			pertage = 0;
		} else { //Perstage
			new_sper = parseFloat(oldsaleprice) * parseFloat(arrnewcal[2])/100;
			saleprice = parseFloat(oldsaleprice)-parseFloat(new_sper);
			newlprice_0 = parseFloat(new_sper);
			pertage = 0;
		}
	} else {
		newlprice=0; saleprice=0; pertage=0; saveAmount=0; newlprice_0=0;
	}	
} else {
	if(arrnewcal[1]=="+"){ //Adding
		if(arrnewcal[3]=="A"){ //Adding
			newlprice = parseFloat(oldListPrice)+parseFloat(arrnewcal[2]);
			saleprice = parseFloat(oldsaleprice)+parseFloat(arrnewcal[2]);
			newlprice_0 = parseFloat(arrnewcal[2]);
			saveAmount = (newlprice-saleprice);
			pertage = parseFloat((parseFloat(saveAmount)/newlprice)*100);
		} else { //Perstage
			new_sper = parseFloat(oldsaleprice) * parseFloat(arrnewcal[2])/100;
			newlprice = parseFloat(oldListPrice)+parseFloat(new_sper);
			saleprice = parseFloat(oldsaleprice)+parseFloat(new_sper);
			newlprice_0 = parseFloat(new_sper);
			saveAmount = (newlprice-saleprice);
			pertage = parseFloat((parseFloat(saveAmount)/newlprice)*100);
		}
	} else if(arrnewcal[1]=="-"){
		if(arrnewcal[3]=="A"){ //Adding
			newlprice = parseFloat(oldListPrice)-parseFloat(arrnewcal[2]);
			saleprice = parseFloat(oldsaleprice)-parseFloat(arrnewcal[2]);
			newlprice_0 = parseFloat(arrnewcal[2]);
			saveAmount = (newlprice-saleprice);
			pertage = parseFloat((parseFloat(saveAmount)/newlprice)*100);
		} else { //Perstage
			new_sper = parseFloat(oldsaleprice) * parseFloat(arrnewcal[2])/100;
			newlprice = parseFloat(oldListPrice)-parseFloat(new_sper);
			saleprice = parseFloat(oldsaleprice)-parseFloat(new_sper);
			newlprice_0 = parseFloat(new_sper);
			saveAmount = (newlprice-saleprice);
			pertage = parseFloat((parseFloat(saveAmount)/newlprice)*100);
		}
	} else {
		newlprice=0; saleprice=0; pertage=0; saveAmount=0; newlprice_0=0;
	}
}
	var retdata = newlprice_0+'|'+pertage+'|'+saveAmount+'|'+arrnewcal[1];
	return retdata;
}
function showimg(myid,orgImage){
	jQuery("#mainImg").attr("src",myid);
	jQuery("#mainImg_link").attr("href",orgImage);
}
function mouseover_vt(myID){
	jQuery("#"+myID).removeClass("buttoncenterG");
	jQuery("#"+myID).addClass("buttoncenter");
}
function mouseout_vt(myID){
	jQuery("#"+myID).removeClass("buttoncenter");
	jQuery("#"+myID).addClass("buttoncenterG");
}
function showresult(){
	jQuery("#votesystem").hide();
	jQuery("#voteController_1").hide();
	jQuery("#resultsystem").show('slow');
	jQuery("#voteController_2").show('slow');
	window.scroll(0,600);
}
function showvote(){
	jQuery("#votesystem").show('slow');
	jQuery("#voteController_1").show();
	jQuery("#resultsystem").hide();
	jQuery("#voteController_2").hide('slow');
	window.scroll(0,800);	
}
function doVote(sPath,qusid,noq){
	var sencmd = false;
	var senval = '';
	for(var a=0;a<noq;a++){
		if(jQuery("input[id='q"+a+"']").is(":checked")){
			sencmd = true;
			senval = jQuery("input[id='q"+a+"']").val();
			break;
		}
	}
	if(sencmd==true){
		jQuery.ajax({
			url : sPath+"postvote.php",
			cache: false,
			data: "tracker=vote&qusid="+qusid+"&chqus="+senval,
			success : function (data) {
				jQuery("#poll_data").html(data);
			}
		});
	}
}
function visithome(){
	document.location.href = 'index.php';
}
function getPreviewText(werb,repUrl,w,h,ids){
		var txtmsg = '<div style="text-align: center;" id="player'+ids+'-parent"><div style=\'border-style: none; overflow: hidden; height: '+h+'px; width: '+w+'px; background-color:#000;\'><div id="player'+ids+'"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a> to see this player.<div style="overflow: hidden; display: none; visibility: hidden; width: 0px; height: 0px;" id="player'+ids+'-config"></div></div><scr'+'ipt type="text/javascript">var s1 = new SWFObject("'+werb+'common/FCKeditor/editor/plugins/flvPlayer/mediaplayer.swf","single","'+w+'","'+(h+19)+'","7");s1.addVariable("width","'+w+'"); s1.addVariable("height","'+(h+19)+'");	s1.addVariable("autostart","true");	s1.addVariable("file","'+repUrl+'");	s1.addVariable("repeat","false");	s1.addVariable("image","");  s1.addVariable("showdownload","false");	s1.addVariable("link","'+repUrl+'"); 	s1.addParam("allowfullscreen","true");	s1.addVariable("showdigits","false"); s1.addParam("wmode","transparent"); s1.addVariable("shownavigation","true");	s1.addVariable("logo",""); s1.addVariable("stretching","none"); s1.write("player'+ids+'");</scr'+'ipt></div></div>';
		return txtmsg;
}
function setFlash(repUrl,w,h,ids){
	var txtmsg_1 = '<div id="player_'+ids+'">\n';
    txtmsg_1 += '<a href="http://get.adobe.com/flashplayer/">\n';
    txtmsg_1 += 'Get the Flash Player</a> to see this player.\n';
    txtmsg_1 += '</div>';
	txtmsg_1 += '<script type="text/javascript">';
	txtmsg_1 += 'var s_'+ids+' = new SWFObject("'+repUrl+'","rotator_'+ids+'","'+w+'","'+h+'","7");';
	txtmsg_1 += 's_'+ids+'.addParam("wmode","transparent");';
	txtmsg_1 += 's_'+ids+'.addParam("quality", "high");';
	txtmsg_1 += 's_'+ids+'.write("player_'+ids+'");';
	txtmsg_1 += '</script>';
	return txtmsg_1;
}
function setCookie(sName, sValue){
  date = new Date();
  document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 2099 23:59:59 GMT;";
  //GetCookie(sName,"Cookie Set: " + sName + "=" + sValue); //For debug output purposes.
}
 
function getcookietime(sName, msg){
  var aCookie = document.cookie.split("; ");
  var out = "Cookie string: " + aCookie; //For debug output purposes.
  for (var i=0; i < aCookie.length; i++){
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) {
		return unescape(aCrumb[1]);
    }
  }
  return null;
}
 
function DelCookie(sName){
  document.cookie = sName + "=; expires=Fri, 21 Dec 1976 04:31:24 GMT;";
}

function setcookietime(sName,sValue,duration){
  date = new Date();
  document.cookie = sName + "=" + escape(sValue) + "; expires=Fri, 31 Dec 2099 23:59:59 GMT;";
}
jQuery.cookie = function(name, value, options) {
    if (typeof value != 'undefined') { // name and value given, set cookie
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
        }
        // CAUTION: Needed to parenthesize options.path and options.domain
        // in the following expressions, otherwise they evaluate to undefined
        // in the packed version for some reason...
        var path = options.path ? '; path=' + (options.path) : '';
        var domain = options.domain ? '; domain=' + (options.domain) : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else { // only name given, get cookie
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                // Does this cookie string begin with the name we want?
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};

function extractNumber(obj, decimalPlaces, allowNegative){
	var temp = obj.value;
	// avoid changing things if already formatted correctly
	var reg0Str = '[0-9]*';
	if (decimalPlaces > 0) {
		reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
	} else if (decimalPlaces < 0) {
		reg0Str += '\\.?[0-9]*';
	}
	reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
	reg0Str = reg0Str + '$';
	var reg0 = new RegExp(reg0Str);
	if (reg0.test(temp)) return true;
	// first replace all non numbers
	var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
	var reg1 = new RegExp(reg1Str, 'g');
	temp = temp.replace(reg1, '');
	if (allowNegative) {
		// replace extra negative
		var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
		var reg2 = /-/g;
		temp = temp.replace(reg2, '');
		if (hasNegative) temp = '-' + temp;
	}
	if (decimalPlaces != 0) {
		var reg3 = /\./g;
		var reg3Array = reg3.exec(temp);
		if (reg3Array != null) {
			// keep only first occurrence of .
			//  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
			var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
			reg3Right = reg3Right.replace(reg3, '');
			reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
			temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
		}
	}
	obj.value = temp;
}
function blockNonNumbers(obj, e, allowDecimal, allowNegative){
	var key;
	var isCtrl = false;
	var keychar;
	var reg;
	if(window.event) {
		key = e.keyCode;
		isCtrl = window.event.ctrlKey
	} else if(e.which) {
		key = e.which;
		isCtrl = e.ctrlKey;
	}
	if (isNaN(key)) return true;
	keychar = String.fromCharCode(key);
	// check for backspace or delete, or if Ctrl was pressed
	if (key == 8 || isCtrl)	{
		return true;
	}
	reg = /\d/;
	var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
	var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
	return isFirstN || isFirstD || reg.test(keychar);
}

function removeHTMLTags(txtID){
 	if(document.getElementById && document.getElementById(txtID)){
 		var strInputCode = document.getElementById(txtID).value; 
 	 	strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "<" : ">";
 		});
 		var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
		return strTagStrippedText;
 	}	
}
function PopupCenter(pageURL, title,w,h) {
		var left = (screen.width/2)-(w/2);
		var top = (screen.height/2)-(h/2);
		var set = "toolbar=no, location=no, status=no, menubar=no, scrollbars=yes, resizable=no, copyhistory=no, width="+w+", height="+h+", top="+top+", left="+left+", directories=no";
		var targetWin = window.open(pageURL,title,set);
} 

function FieldValided(sFrmName,sFieldName){
	return jQuery('#'+sFrmName).validate().element('#'+sFieldName);
}

//Valided the Form
function ValidForm(frmName){
	//Search for all Input Area with isreq=1
		jQuery.validator.addMethod("field", function(value, element) {
			return value != 0;
		}, "&nbsp;");
		jQuery("#form1").validate({
			errorPlacement: function(error, element) { 
				error.appendTo(element.next() ); 
			},			
			invalidHandler: function(e, validator) {
				var errors = validator.numberOfInvalids();
				if (errors) {
					var message = errors == 1
						? 'You missed 1 field. It has been highlighted below'
						: 'You missed ' + errors + ' fields.  They have been highlighted below';					
						jQuery("div.error span.msg").html(message);
					jQuery("div.error").show();
				} else {
					jQuery("div.error").hide();
				}
			},
			onkeyup: false,
			success: function(label) { 
				label.html("&nbsp;").toggleClass("valid"); 
	        },debug:true
		});
	if(jQuery("#form1").valid()){
		document.getElementById("form1").submit();
	}
}