// Author: M Haris Munir
// Author Email: haris.multi@gmail.com
// Last Updated: Monday, December 07, 2009

var hr = {
	setCookie:function(c_name,value,expiredays){
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString()) + ";path=/";
	},
	getCookie:function (c_name){
		if (document.cookie.length>0)
		  {
		  c_start=document.cookie.indexOf(c_name + "=");
		  if (c_start!=-1)
			{ 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
			} 
		  }
		return "";
	},
	// Explode Function Same Like PHP
	// version: 1.0.0.0
	// LastUpdate: 27-03-2009
	explode:function(f,value){
		var get = Array();
		var newval = value;
		var newf = f;
		for(var i=0; i<value.length; i++){
			var nv = newval.indexOf(newf);
			if(nv < 0){
				if(newval=='') return get;
				get[i] = newval;
				return get;
			}else{
				var nvv = nv + 1;
				var ne = newval.slice(0,nv);
				//alert(ne)
				newval = newval.slice(nvv);
				get[i] = ne;
			}
		}
	},
	$:function (id){
		try{
			return document.getElementById(id);
		}catch(e){
			return false;
		}
	},
	rand:function (limit){
			if(!limit) limit=6;
			var ra = Math.ceil(Math.random()*999999);
			ra = ((ra*ra)*Math.ceil(Math.random()*ra));
			ra = ra + 'i';
			return ra.substr(3,limit);
	},
	print_r: function (obj,r){
		var ret = '';
		for(var v in obj){
			ret += v + '\r\n';
		}
		if(r) return ret; else alert(ret);
	},
	trim: function (str, charlist) {
		str += '';
		if (!charlist) {
			// default list
			whitespace = " \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000";
		} else {
			// preg_quote custom list
			charlist += '';
			whitespace = charlist.replace(/([\[\]\(\)\.\?\/\*\{\}\+\$\^\:])/g, '$1');
		}
		l = str.length;
		for (i = 0; i < l; i++) {
			if (whitespace.indexOf(str.charAt(i)) === -1) {
				str = str.substring(i); break;
			}
		}
		l = str.length;
		for (i = l - 1; i >= 0; i--) {
			if (whitespace.indexOf(str.charAt(i)) === -1) {
				str = str.substring(0, i + 1); break;
			}
		}
		return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
	}

}

function number_format(number,decimals,dec_point,thousands_sep){
	var n=number,prec=decimals;var toFixedFix=function(n,prec){var k=Math.pow(10,prec);return(Math.round(n*k)/k).toString();};n=!isFinite(+n)?0:+n;prec=!isFinite(+prec)?0:Math.abs(prec);var sep=(typeof thousands_sep==='undefined')?',':thousands_sep;var dec=(typeof dec_point==='undefined')?'.':dec_point;var s=(prec>0)?toFixedFix(n,prec):toFixedFix(Math.round(n),prec);var abs=toFixedFix(Math.abs(n),prec);var _,i;if(abs>=1000){_=abs.split(/\D/);i=_[0].length%3||3;_[0]=s.slice(0,i+(n<0))+
_[0].slice(i).replace(/(\d{3})/g,sep+'$1');s=_.join(dec);}else{s=s.replace('.',dec);}
var decPos=s.indexOf(dec);if(prec>=1&&decPos!==-1&&(s.length-decPos-1)<prec){s+=new Array(prec-(s.length-decPos-1)).join(0)+'0';}
else if(prec>=1&&decPos===-1){s+=dec+new Array(prec).join(0)+'0';}
return s;
}

var hr_hasFlash=function(){var a=6;if(navigator.appVersion.indexOf("MSIE")!=-1&&navigator.appVersion.indexOf("Windows")>-1){document.write('<script language="VBScript"\> \non error resume next \nhasFlash = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash." & '+a+'))) \n</script\> \n');if(window.hasFlash!=null)return window.hasFlash}if(navigator.mimeTypes&&navigator.mimeTypes["application/x-shockwave-flash"]&&navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){var b=(navigator.plugins["Shockwave Flash 2.0"]||navigator.plugins["Shockwave Flash"]).description;return parseInt(b.substr(b.indexOf(".")-2,2),10)>=a}return false}();

function flvTxt(obj){

	var hasFlash2 = hr_hasFlash;
	
	if(!hasFlash2) return false;
	
	if(typeof obj == 'object'){
		if(!obj.txt){
			return false;
		}
		obj.txtColor = obj.txtColor||'#776813';
		obj.bgColor = obj.bgColor||'#FFFFFF';
		obj.width = obj.width||'750';
		obj.height = obj.height||'39';
		var str = "Hello ";
	}else{
		return false;
	}
	var embed = '<object height="'+obj.height+'" width="'+obj.width+'" type="application/x-shockwave-flash" data="/javascript/sifr/vivodtext.swf" style="width: '+obj.width+'px; height: '+obj.height+'px;"><param name="flashvars" value="txt='+ obj.txt +'&amp;textcolor='+obj.txtColor+'&amp;w='+obj.width+'&amp;h='+obj.height+'"><param name="movie" value="/javascript/sifr/vivodtext.swf"><param name="wmode" value="opaque"><param name="bgcolor" value="'+ obj.bgColor +'"><param name="allowScriptAccess" value="always"><param name="quality" value="best"><embed height="'+obj.height+'" width="'+obj.width+'" src="/javascript/sifr/vivodtext.swf" quality="best" flashvars="txt='+ obj.txt +'&amp;textcolor='+obj.txtColor+'&amp;w='+obj.width+'&amp;h='+obj.height+'" wmode="opaque" bgcolor="'+ obj.bgColor +'" type="application/x-shockwave-flash" class="sIFR-flash" style="width: '+obj.width+'px; height: '+obj.height+'px;"></object>';
	
	if(obj.id){
		if(typeof obj.id == 'object'){
			for(var x=0; x<obj.id.length; x++){
				document.getElementById(obj.id[x]).innerHTML = embed;
			}
		}else if(typeof obj.id == 'string'){
			document.getElementById(obj.id).innerHTML = embed;
		}
	}else{
		return embed;
	}

	return true;
}


///////////////////

var liveContent = {
	addContet:'',
	load: function (){
		try{
			if(typeof change_prodd=='object'){
				change_prodd.change('i');
			}
			if(!hr_pageblock.pageload){
				hr_pageblock.init();
			}
			hr_pageblock.onresize();
			hr_pageblock.apply(function($){
				var Objid = $.id;
				show_MC(Objid,50);
				document.getElementById('wdliveclose').onclick = function (){
					show_MC(Objid,50);
					liveContent.iframe.remove();
					var Objzimg = document.getElementById('wdlivecontent');
					Objzimg.style.display='none';
				}
			})
			hr_pageblock.resizepost = function (getsize){
				var Objzimg = document.getElementById('wdlivecontent');
				var midPoint = Math.ceil(getsize[0]/2) - (Objzimg.offsetWidth/2);
				Objzimg.style.left = midPoint + 'px';
			}
			var Objzimg = document.getElementById('wdlivecontent');
			Objzimg.style.display = '';
			Objzimg.style.top = '10px';
			hr_pageblock.resizepost(hr_pageblock.getSize());
			//var giaframe = hr_pageblock.iframe.create(u);
			//hr_pageblock.iframe.loading();
		}catch(e){
			return true;
		}
		return false;
	},
	iframe: {
		create: function (url){
			var parant = document.getElementById('wdlivearea');
			var newiframe = document.createElement('iframe');
			newiframe.src = url;
			newiframe.id = 'wdliveinner';
			var bwheight = document.documentElement.clientHeight
			if(bwheight > document.body.clientHeight || bwheight <= 0){
				bwheight = document.body.clientHeight;
			}
			newiframe.style.height = (bwheight-(20+24)) + 'px';
			newiframe.className = 'wdliveinner';
			newiframe.setAttribute('frameborder','0');
			parant.appendChild(newiframe);
			return newiframe;
		},
		/*create: function (url){
			var parant = document.getElementById('wdlivearea');
			var newiframe = document.createElement('iframe');
			newiframe.src = url;
			newiframe.id = 'wdliveinner';
			newiframe.style.height = (document.body.clientHeight-(20+24)) + 'px';
			newiframe.className = 'wdliveinner';
			newiframe.setAttribute('frameborder','0');
			parant.appendChild(newiframe);
			return newiframe;
		},*/
		createImg: function (url,width,height){
			var parant = document.getElementById('wdlivearea');
			var newiimg = document.createElement('img');
			newiimg.src = url;
			newiimg.id = 'wdliveinner';
			
			if(height) newiimg.height = height;
			if(width) newiimg.width = width;
			
			newiimg.className = 'wdliveinnerimg';
			parant.appendChild(newiimg);
			return newiimg;
		},
		remove: function (){
			document.getElementById('wdlivearea').removeChild(document.getElementById('wdliveinner'));
		},
		loading: function (){
			//document.getElementById('gialoading').style.display = 'block';
		}
	},
	top: function(){
		jQuery('html,body').animate({
			scrollTop: 0
		},1000);
	},
	content: {
		feedback: function (){
			liveContent.iframe.create('/feedback.shtml');
			liveContent.load();
			liveContent.top();
		},
		appointment: function (){
			try{
			liveContent.iframe.create('http://www.supersaas.com/schedule/vivodiamonds/Showroom_Visit');
			liveContent.load();
			liveContent.top();
			}catch(e){
				return true;
			}
			return false;
		},
		ddetailVideo: function (){
			try{
			liveContent.iframe.create('http://www.youtube.com/embed/RVSU4I-BYS8');
			liveContent.load();
			liveContent.top();
			}catch(e){
				return true;
			}
			return false;
		},
		testimonials: function (c){
			liveContent.iframe.createImg(c,650,488);
			liveContent.load();
			liveContent.top();
		}
	}
}
